source: PostgreSqlDotnetCore/Models/UsersClass.cs@ a850333

main
Last change on this file since a850333 was 2aea0fd, checked in by ElenaMoskova <elena.moskova99@…>, 2 months ago

init commit Elena

  • Property mode set to 100644
File size: 2.8 KB
Line 
1using Microsoft.AspNetCore.Identity;
2using System;
3using System.Collections.Generic;
4using System.ComponentModel.DataAnnotations;
5using System.ComponentModel.DataAnnotations.Schema;
6using System.Linq;
7using System.Web;
8
9namespace PostgreSqlDotnetCore.Models
10{
11 [Table("users", Schema = "project")]
12 public class UsersClass
13 {
14
15
16 Dictionary<int, string> roles = new Dictionary<int, string>();
17 Dictionary<int, string> jobes = new Dictionary<int, string>();
18 public UsersClass()
19 {
20 pupulateRoles();
21 pupulateJobs();
22 }
23
24 private void pupulateRoles()
25 {
26 roles.Add(RoleConstants.Admin, "admin");
27 roles.Add(RoleConstants.Standard, "standard");
28 roles.Add(RoleConstants.Manager, "manager");
29 }
30
31 private void pupulateJobs()
32 {
33 jobes.Add(1, "doctor");
34 jobes.Add(2, "secretary");
35 jobes.Add(3, "manager");
36 jobes.Add(4, "developer");
37 jobes.Add(5, "HR");
38 }
39
40 public UsersClass(string email, string name, string lastname, string password, string number, int role_id, int? jobs_id)
41 {
42 pupulateRoles();
43
44 this.email = email;
45 this.name = name;
46 this.lastname = lastname;
47 this.password = password;
48 this.number = number;
49 this.role_id = role_id;
50 this.jobs_id = jobs_id;
51 }
52
53 [Key]
54 public int id { get; set; }
55 [Required(ErrorMessage = "The email address is required")]
56 [DataType(DataType.EmailAddress, ErrorMessage = "Invalid Email Address")]
57 public string email { get; set; }
58 [Required(ErrorMessage = "The customer name is required")]
59 public string name { get; set; }
60 [Required(ErrorMessage = "The customer lastname is required")]
61 public string lastname { get; set; }
62 //[NotMapped]
63 public string? password { get; set; }
64
65 [Required(ErrorMessage = "The number is required")]
66 public string number { get; set; }
67 public int role_id { get; set; }
68 public int? jobs_id { get; set; }
69
70
71 public string GetRoleName
72 {
73 get
74 {
75 return roles.ContainsKey(role_id) ? roles[role_id] : role_id.ToString();
76 }
77 }
78
79 public string? GetJobName
80 {
81 get
82 {
83 try
84 {
85 if (jobs_id == null)
86 {
87 return "-";
88 }
89 return jobes.ContainsKey((int)jobs_id) ? jobes[(int)jobs_id] : jobs_id.ToString();
90 } catch (Exception e)
91 {
92 return "-";
93 }
94 }
95 }
96
97
98 }
99}
Note: See TracBrowser for help on using the repository browser.