From e6523d7f312173e052e83ebe11963a0256fa3ca9 Mon Sep 17 00:00:00 2001 From: Malek Ajmi Date: Fri, 9 Jul 2021 13:51:10 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Cr=C3=A9ation=20du=20Sch=C3=A9ma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Models/Profile.cs | 20 ++++++++++++++++ Models/Task.cs | 53 +++++++++++++++++++++++++++++++++++++++++ Models/User.cs | 49 +++++++++++++++++++++++++++++++++++++ UserTasksManager.csproj | 1 - 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 Models/Profile.cs create mode 100644 Models/Task.cs create mode 100644 Models/User.cs diff --git a/Models/Profile.cs b/Models/Profile.cs new file mode 100644 index 0000000..47fc00b --- /dev/null +++ b/Models/Profile.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace UserTasksManager.Models +{ + public enum Role + { + Developer, + Manager + } + public class Profile : User + { + public Role role { get; set; } + //Tasks + public ICollection tasks { get; set; } + + } +} diff --git a/Models/Task.cs b/Models/Task.cs new file mode 100644 index 0000000..0645c32 --- /dev/null +++ b/Models/Task.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; + +namespace UserTasksManager.Models +{ + public class Task + { + public enum State + { + ToDO, + InDevelopment, + InCodeReview, + Testing, + Done + } + public int Id { get; set; } + public string Title { get; set; } + public string Description { get; set; } + private string startDate; + + public string StartDate + { + get { return startDate; } + set { startDate = DateTime.Now.ToString(); } + } + private string endDate; + + public string EndDate + { + get { return endDate; } + set + { + DateTime parsedDate; + var isValidFormat = DateTime.TryParseExact(value,"MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out parsedDate); + if (isValidFormat) + { + endDate = value; + } + else + { + endDate = "Invalid"; + } + } + } + public float Estimate { get; set; } + public State Status { get; set; } + //Profile + public ICollection profiles { get; set; } + } +} diff --git a/Models/User.cs b/Models/User.cs new file mode 100644 index 0000000..9d8839c --- /dev/null +++ b/Models/User.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace UserTasksManager.Models +{ + public class User + { + public int Id { get; set; } + public string UserName { get; set; } + private string password; + + public string Password + { + get { return password; } + set + { + if (value.Length < 5 || value.Length > 20) + { + Console.WriteLine("Votre mot de passe doit contenir entre 5 et 20 caractéres"); + } + else + { + password = value; + } + } + } + private string confirmPassword; + + public string ConfirmPassword + { + get { return confirmPassword; } + set + { + if (value.Equals(Password)) + { + confirmPassword = value; + } + else + { + Console.WriteLine("Les deux mdp sont pas identiques"); + } + } + } + public string Email { get; set; } + public DateTime DateCreated { get; set; } + } +} diff --git a/UserTasksManager.csproj b/UserTasksManager.csproj index e56f9db..8ece29d 100644 --- a/UserTasksManager.csproj +++ b/UserTasksManager.csproj @@ -6,7 +6,6 @@ - From d6d51704ffe6b6d97ee3280c632b5582ac8f538e Mon Sep 17 00:00:00 2001 From: Malek Ajmi Date: Fri, 9 Jul 2021 15:56:07 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Pr=C3=A9parer=20le=20terrain=20pour=20l'uti?= =?UTF-8?q?lisation=20des=20annotations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data/IUserTasksManager.cs | 12 ++++++++++++ Data/UserTasksContext.cs | 11 +++++++++++ Models/User.cs | 40 ++++++++------------------------------- Startup.cs | 4 ++++ UserTasksManager.csproj | 11 ++++++++++- 5 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 Data/IUserTasksManager.cs create mode 100644 Data/UserTasksContext.cs diff --git a/Data/IUserTasksManager.cs b/Data/IUserTasksManager.cs new file mode 100644 index 0000000..ed61601 --- /dev/null +++ b/Data/IUserTasksManager.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace UserTasksManager.Data +{ + interface IUserTasksManager + { + + } +} diff --git a/Data/UserTasksContext.cs b/Data/UserTasksContext.cs new file mode 100644 index 0000000..cf4af98 --- /dev/null +++ b/Data/UserTasksContext.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace UserTasksManager.Data +{ + public class UserTasksContext + { + } +} diff --git a/Models/User.cs b/Models/User.cs index 9d8839c..bbb4ce0 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -9,41 +9,17 @@ public class User { public int Id { get; set; } public string UserName { get; set; } - private string password; - public string Password - { - get { return password; } - set - { - if (value.Length < 5 || value.Length > 20) - { - Console.WriteLine("Votre mot de passe doit contenir entre 5 et 20 caractéres"); - } - else - { - password = value; - } - } - } - private string confirmPassword; + public string Password { get; set; } + public string ConfirmPassword { get; set; } + public string Email { get; set; } + private DateTime dateCreated; - public string ConfirmPassword + public DateTime DateCreated { - get { return confirmPassword; } - set - { - if (value.Equals(Password)) - { - confirmPassword = value; - } - else - { - Console.WriteLine("Les deux mdp sont pas identiques"); - } - } + get { return dateCreated; } + set { dateCreated = DateTime.Now; } } - public string Email { get; set; } - public DateTime DateCreated { get; set; } + } } diff --git a/Startup.cs b/Startup.cs index 7624b9d..061bc6d 100644 --- a/Startup.cs +++ b/Startup.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using UserTasksManager.Models; namespace UserTasksManager { @@ -25,6 +26,9 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + //les services tels que le contexte de base de données doivent être inscrits auprès du conteneur d’injection de dépendances. + //Le conteneur fournit le service aux contrôleurs. + services.AddControllers(); } diff --git a/UserTasksManager.csproj b/UserTasksManager.csproj index 8ece29d..5979a6f 100644 --- a/UserTasksManager.csproj +++ b/UserTasksManager.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 @@ -8,6 +8,15 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + From 1c92ae3aaaa8315b364dd504f78f902f46c5c3e8 Mon Sep 17 00:00:00 2001 From: Malek Ajmi Date: Mon, 12 Jul 2021 13:07:20 +0100 Subject: [PATCH 3/3] Annotations --- Models/Profile.cs | 2 ++ Models/Task.cs | 14 +++++++++----- Models/User.cs | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Models/Profile.cs b/Models/Profile.cs index 47fc00b..86e4d7c 100644 --- a/Models/Profile.cs +++ b/Models/Profile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; @@ -12,6 +13,7 @@ public enum Role } public class Profile : User { + [Required(ErrorMessage = "Role is Required (must be Developer or Manager)")] public Role role { get; set; } //Tasks public ICollection tasks { get; set; } diff --git a/Models/Task.cs b/Models/Task.cs index 0645c32..21b7dc9 100644 --- a/Models/Task.cs +++ b/Models/Task.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -17,17 +18,19 @@ public enum State Done } public int Id { get; set; } + [Required(ErrorMessage = "Your task must hava a title")] public string Title { get; set; } + [DataType(DataType.MultilineText)] public string Description { get; set; } - private string startDate; - - public string StartDate + private DateTime startDate; + public DateTime StartDate { get { return startDate; } - set { startDate = DateTime.Now.ToString(); } + set { startDate = DateTime.Now; } } + [Required(ErrorMessage = "End Date is Required!")] + [DataType(DataType.Date)] private string endDate; - public string EndDate { get { return endDate; } @@ -45,6 +48,7 @@ public string EndDate } } } + [Range(0, float.MaxValue, ErrorMessage = "Please enter valid float Number")] public float Estimate { get; set; } public State Status { get; set; } //Profile diff --git a/Models/User.cs b/Models/User.cs index bbb4ce0..00f81ff 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Threading.Tasks; @@ -7,11 +9,23 @@ namespace UserTasksManager.Models { public class User { + [Key] // optional ! public int Id { get; set; } + [Required(ErrorMessage = "UserName is required")] public string UserName { get; set; } - + [Required(ErrorMessage = "Password is required")] + [DataType(DataType.Password)] + [RegularExpression("^((?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])|(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z0-9])|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$" + , ErrorMessage = "Passwords must be at least 8 characters and contain at 3 of 4 of the following: upper case (A-Z), lower case (a-z), number (0-9) and special character (e.g. !@#$%^&*)")] public string Password { get; set; } + [NotMapped] //Confirm Password will not be added to DB + [Required(ErrorMessage = "Confirm Password is required")] + [DataType(DataType.Password)] + [Compare("Password", ErrorMessage = "Password and Confirmation Password must match.")] public string ConfirmPassword { get; set; } + [Required(ErrorMessage = "Email is required")] + // data annotation to validate email in C# + [EmailAddress(ErrorMessage = "Enter a valid Email address")] public string Email { get; set; } private DateTime dateCreated;