Класс, который представляет собой ViewModel для аккаунтов. DTO с валидационной логикой.
예제 #1
0
 public ActionResult Delete(AccountViewModel account)
 {
     try
     {
         accountService.Delete(account);
         accountService.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         ModelState.AddModelError("", "Unable to save changes");
     }
     return View(account);
 }
예제 #2
0
 /// <summary>
 /// Обновление аккаунта
 /// </summary>
 /// <param name="account"></param>
 public void Edit(AccountViewModel account)
 {
     repository.Update(Convert(account));
 }
예제 #3
0
 /// <summary>
 /// Удаление аккаунта
 /// </summary>
 /// <param name="account"></param>
 public void Delete(AccountViewModel account)
 {
     repository.Delete(Convert(account));
 }
예제 #4
0
 /// <summary>
 /// Добавление аккаунта в репозиторий
 /// </summary>
 /// <param name="account"></param>
 public void Add(AccountViewModel account)
 {
     repository.Add(Convert(account));
 }
예제 #5
0
 /// <summary>
 /// Конвертационные функции
 /// </summary>
 private User Convert(AccountViewModel c)
 {
     return new User()
     {
         Id = c.Id,
         Login = c.Login,
         Email = c.Email,
         PasswordHash = c.Password,
         Role = c.Role,
         CreatedDate = DateTime.Now,
         UpdatedDate = DateTime.Now,
         Status = System.Convert.ToByte(c.IsActive)
     };
 }
예제 #6
0
 public ActionResult Edit(AccountViewModel account)
 {
     try
     {
         if (ModelState.IsValid)
         {
             account.Password = hasher.Hash(account.Password);
             accountService.Edit(account);
             accountService.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", "Unable to save changes");
     }
     return View(account);
 }
예제 #7
0
 public ActionResult New()
 {
     AccountViewModel model = new AccountViewModel();
     return View(model);
 }