コード例 #1
0
 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;
 }
コード例 #2
0
        public async Task <IActionResult> Delete(DataUserAccountDTO userAccount)
        {
            if (userAccount == null)
            {
                return(RedirectToAction(nameof(Error)));
            }

            await _userService.Delete(userAccount.Id);

            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
 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,
         }
     });
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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());
            }
        }