Set user groups

This commit is contained in:
Andre Beging
2022-04-08 16:12:51 +02:00
parent 38eec13a1b
commit c553047369
3 changed files with 62 additions and 11 deletions

View File

@@ -19,6 +19,9 @@ namespace FoodsharingSiegen.Server.Data.Service
return new OperationResult<User>(new Exception("Diese E-Mail Adresse wird bereits verwendet"));
user.Created = DateTime.UtcNow;
if (string.IsNullOrWhiteSpace(user.Password))
user.Password = string.Empty;
await Context.Users.AddAsync(user);
@@ -38,7 +41,15 @@ namespace FoodsharingSiegen.Server.Data.Service
{
try
{
Context.Users.Update(user);
var entityUser = await Context.Users.FirstOrDefaultAsync(x => x.Id == user.Id);
if (entityUser == null) return new OperationResult(new Exception("User not found"));
entityUser.Mail = user.Mail;
entityUser.Name = user.Name;
entityUser.Type = user.Type;
entityUser.Verified = user.Verified;
entityUser.Groups = user.Groups;
var saveR = await Context.SaveChangesAsync();
if(saveR < 1) return new OperationResult(new Exception("Fehler beim speichern"));