public void Execute(RegisterUserDto request) { _validator.ValidateAndThrow(request); var user = _mapper.Map <User>(request); user.RoleId = (int)Roles.User; _context.Users.Add(user); var useCases = new List <UserUserCase>(); foreach (var usecase in RightListes.UserRights()) { useCases.Add(new UserUserCase { Id = user.Id, UseCaseId = usecase }); } user.UserUserCases = useCases; _context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Succesfull registration! </h1>", SendTo = request.Email, Subject = "Registration" }); }
public void Execute(UserAddDto request) { _validator.ValidateAndThrow(request); var user = _context.Users.Include(x => x.UserUserCases).FirstOrDefault(x => x.Id == request.Id); if (user == null) { throw new EntityNotFoundException(request.Id, typeof(User)); } _maper.Map(request, user); var useCases = new List <UserUserCase>(); if (request.UseCases.Count() == 0) { if (user.RoleId == (int)Roles.Admin) { foreach (var useCase in RightListes.AdminRights()) { useCases.Add(new UserUserCase { UseCaseId = useCase, UserId = user.Id }); } } } if (user.RoleId == (int)Roles.User) { foreach (var useCase in RightListes.UserRights()) { useCases.Add(new UserUserCase { UseCaseId = useCase, UserId = user.Id }); } } if (user.RoleId != (int)Roles.User || user.RoleId != (int)Roles.Admin) { foreach (var useCase in request.UseCases) { useCases.Add(new UserUserCase { UseCaseId = useCase, UserId = user.Id }); } } user.UserUserCases = useCases; _context.SaveChanges(); }
public void Execute(UserAddDto request) { request.Id = 0; _validator.ValidateAndThrow(request); _context.Users.Add(_maper.Map <User>(request)); _context.SaveChanges(); var user = _context.Users.Include(x => x.UserUserCases).FirstOrDefault(x => x.Username == request.Username); var useCases = new List <UserUserCase>(); if (user.RoleId == (int)Roles.Admin) { foreach (var useCase in RightListes.AdminRights()) { useCases.Add(new UserUserCase { UseCaseId = useCase, UserId = user.Id }); } } if (user.RoleId == (int)Roles.User) { foreach (var useCase in RightListes.UserRights()) { useCases.Add(new UserUserCase { UseCaseId = useCase, UserId = user.Id }); } } if (user.RoleId != (int)Roles.User || user.RoleId != (int)Roles.Admin) { foreach (var useCase in request.UseCases) { useCases.Add(new UserUserCase { UseCaseId = useCase, UserId = user.Id }); } } user.UserUserCases = useCases; _context.SaveChanges(); }