Browse Source

Agents added on a agency

master
LeneS 5 years ago
parent
commit
b97515ba07

+ 1
- 0
UnivateProperties_API/Controllers/Users/AgentController.cs View File

34
         {
34
         {
35
             using (var scope = new TransactionScope())
35
             using (var scope = new TransactionScope())
36
             {
36
             {
37
+                
37
                 _Repo.Insert(agent);
38
                 _Repo.Insert(agent);
38
                 scope.Complete();
39
                 scope.Complete();
39
                 return CreatedAtAction(nameof(Get), new { id = agent.Id }, agent);
40
                 return CreatedAtAction(nameof(Get), new { id = agent.Id }, agent);

+ 2
- 4
UnivateProperties_API/Controllers/Users/RegisterController.cs View File

50
                 Subject = new ClaimsIdentity(new Claim[]
50
                 Subject = new ClaimsIdentity(new Claim[]
51
                 {
51
                 {
52
                     new Claim(ClaimTypes.Name, user.Id.ToString()),
52
                     new Claim(ClaimTypes.Name, user.Id.ToString()),
53
-                    new Claim(ClaimTypes.Role, user.Role)
53
+                    //new Claim(ClaimTypes.Role, user.Role)
54
                 }),
54
                 }),
55
                 Expires = DateTime.UtcNow.AddMinutes(15),
55
                 Expires = DateTime.UtcNow.AddMinutes(15),
56
                 SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
56
                 SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
57
             };
57
             };
58
             var token = tokenHandler.CreateToken(tokenDescriptor);
58
             var token = tokenHandler.CreateToken(tokenDescriptor);
59
-            var tokenString = tokenHandler.WriteToken(token);
59
+            var tokenString = tokenHandler.WriteToken(token); 
60
 
60
 
61
             // return basic user info (without password) and token to store client side
61
             // return basic user info (without password) and token to store client side
62
             return Ok(new
62
             return Ok(new
63
             {
63
             {
64
                 user.Id,
64
                 user.Id,
65
                 user.Username,
65
                 user.Username,
66
-                user.Name,
67
-                user.Surname,
68
                 Token = tokenString
66
                 Token = tokenString
69
             });
67
             });
70
         }
68
         }

+ 1
- 0
UnivateProperties_API/Controllers/Users/UserController.cs View File

7
 
7
 
8
 namespace User_API.Controllers
8
 namespace User_API.Controllers
9
 {
9
 {
10
+    //[Authorize]
10
     [Route("api/[controller]")]
11
     [Route("api/[controller]")]
11
     [ApiController]
12
     [ApiController]
12
     public class UserController : ControllerBase
13
     public class UserController : ControllerBase

+ 0
- 2
UnivateProperties_API/Model/Users/User.cs View File

10
         #endregion Constructor
10
         #endregion Constructor
11
 
11
 
12
         #region Properties
12
         #region Properties
13
-        public string Name { get; set; }
14
-        public string Surname { get; set; }
15
         public string Username { get; set; }
13
         public string Username { get; set; }
16
         public string Role { get; set; }
14
         public string Role { get; set; }
17
         public byte[] PasswordHash { get; set; }
15
         public byte[] PasswordHash { get; set; }

+ 9
- 1
UnivateProperties_API/Repository/Users/AgentRepository.cs View File

42
 
42
 
43
         public void Insert(Agent item)
43
         public void Insert(Agent item)
44
         {
44
         {
45
+            if (item.AgencyId != 0 && item.Agency == null)
46
+            {
47
+                AgencyRepository arepo = new AgencyRepository(_dbContext);
48
+                item.Agency = arepo.Get(a => a.Id == item.AgencyId).FirstOrDefault();
49
+            }
45
             _dbContext.Add(item);
50
             _dbContext.Add(item);
46
             Save();
51
             Save();
47
         }
52
         }
48
 
53
 
49
         public void Insert(IEnumerable<Agent> item)
54
         public void Insert(IEnumerable<Agent> item)
50
         {
55
         {
51
-            _dbContext.Add(item);
56
+            foreach (var i in item)
57
+            {
58
+                _dbContext.Add(item);
59
+            }
52
             Save();
60
             Save();
53
         }
61
         }
54
 
62
 

+ 0
- 2
UnivateProperties_API/Repository/Users/RegisterRepository.cs View File

165
             }
165
             }
166
 
166
 
167
             // update user properties
167
             // update user properties
168
-            user.Name = userParam.Name;
169
-            user.Surname = userParam.Surname;
170
             user.Username = userParam.Username;
168
             user.Username = userParam.Username;
171
 
169
 
172
             // update password if it was entered
170
             // update password if it was entered

+ 0
- 2
UnivateProperties_API/Repository/Users/UserRepository.cs View File

103
             }
103
             }
104
 
104
 
105
             // update user properties
105
             // update user properties
106
-            user.Name = userParam.Name;
107
-            user.Surname = userParam.Surname;
108
             user.Username = userParam.Username;
106
             user.Username = userParam.Username;
109
 
107
 
110
             // update password if it was entered
108
             // update password if it was entered

+ 7
- 4
UnivateProperties_API/UnivateProperties_API.csproj View File

5
     <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
5
     <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
6
   </PropertyGroup>
6
   </PropertyGroup>
7
 
7
 
8
+  <ItemGroup>
9
+    <Compile Remove="Migrations\**" />
10
+    <Content Remove="Migrations\**" />
11
+    <EmbeddedResource Remove="Migrations\**" />
12
+    <None Remove="Migrations\**" />
13
+  </ItemGroup>
14
+
8
   <ItemGroup>
15
   <ItemGroup>
9
     <Compile Remove="Model\Users\AgencyAgent.cs" />
16
     <Compile Remove="Model\Users\AgencyAgent.cs" />
10
   </ItemGroup>
17
   </ItemGroup>
20
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
27
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
21
   </ItemGroup>
28
   </ItemGroup>
22
 
29
 
23
-  <ItemGroup>
24
-    <Folder Include="Migrations\" />
25
-  </ItemGroup>
26
-
27
 </Project>
30
 </Project>

Loading…
Cancel
Save