public void Execute(AddUser request) { _validator.ValidateAndThrow(request); var userDto = new Domain.User { IsDeleted = false, FirstName = request.FirstName, LastName = request.LastName, CreatedAt = DateTime.Now, ModifidedAt = null, UserName = request.UserName }; if (Context.Users.Any(u => u.UserName == userDto.UserName)) { throw new EntityAllreadyExists("User"); } try { Context.SaveChanges(); _sender.Send(new SendEmailDto { Content = "<h1>Uspesno ste dodali korisnika</h1>", SendTo = request.Email, Subject = "Registration confirmation!!!" }); } catch (Exception) { throw; } }
public void Execute(UserDto request) { request.Password = CommonMethods.ConvertToEncrypt(request.Password); var user = mapper.Map <User>(request); validator.ValidateAndThrow(request); context.Users.Add(user); context.SaveChanges(); }