public ErrorsCollection Create(UserPostModel createInfo) { var errors = createValidator.Validate(createInfo, context); if (errors != null) { return(errors); } User toAdd = new User { FirstName = createInfo.FirstName, LastName = createInfo.LastName, Email = createInfo.Email, Username = createInfo.UserName, Password = ComputeSha256Hash(createInfo.Password), UserUserRoles = new List <UserUserRole>() }; var defaultRole = context .UserRoles .FirstOrDefault(urole => urole.Name == UserRoles.Regular); context.Users.Add(toAdd); context.UserUserRoles.Add(new UserUserRole { User = toAdd, UserRole = defaultRole, StartTime = DateTime.Now, EndTime = null }); context.SaveChanges(); return(null); }
public async Task <TVm> Process(TVm input) { await _createValidator.Validate(input); var coreModel = await _mapper.ToCoreModel(input); var dbResult = await _dbCreate.Create(coreModel); var vmResult = await _mapper.ToViewModel(dbResult); return(vmResult); }