public static void ToUser(this DataUserAccountDTO userAccount, User user) { user.Name = userAccount.Name; user.DisplayName = string.Concat(userAccount.Name.Split(" ").FirstOrDefault(), " ", userAccount.Name.Split(" ").LastOrDefault()); user.Status = userAccount.Status; user.Active = userAccount.Active; user.Account.UserName = userAccount.UserName; }
public async Task <IActionResult> Delete(DataUserAccountDTO userAccount) { if (userAccount == null) { return(RedirectToAction(nameof(Error))); } await _userService.Delete(userAccount.Id); return(RedirectToAction(nameof(Index))); }
public static User ToUser(this DataUserAccountDTO userAccount) { return(new User() { Name = userAccount.Name, DisplayName = string.Concat(userAccount.Name.Split(" ").FirstOrDefault(), " ", userAccount.Name.Split(" ").LastOrDefault()), Status = userAccount.Status, Active = userAccount.Active, Account = new Account() { UserName = userAccount.UserName, } }); }
public async Task Update(DataUserAccountDTO userAccount) { var user = GetById(userAccount.Id); if (user.Account.UserName != userAccount.UserName && _userRepository.ExistUser(userAccount.ToUser())) { throw new Exception("User Exist"); } userAccount.ToUser(user); _userRepository.Update(user); await _userRepository.UnitOfWork.SaveChangesAsync().ConfigureAwait(false); }
public async Task <IActionResult> Edit(DataUserAccountDTO user) { if (user == null) { return(RedirectToAction(nameof(Error))); } try { await _userService.Update(user); return(RedirectToAction(nameof(Index))); } catch (Exception e) { ViewData["UserExist"] = "User Exist!"; return(View()); } }