Класс, который представляет собой ViewModel для аккаунтов. DTO с валидационной логикой.
Esempio n. 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);
 }
Esempio n. 2
0
 /// <summary>
 /// Обновление аккаунта
 /// </summary>
 /// <param name="account"></param>
 public void Edit(AccountViewModel account)
 {
     repository.Update(Convert(account));
 }
Esempio n. 3
0
 /// <summary>
 /// Удаление аккаунта
 /// </summary>
 /// <param name="account"></param>
 public void Delete(AccountViewModel account)
 {
     repository.Delete(Convert(account));
 }
Esempio n. 4
0
 /// <summary>
 /// Добавление аккаунта в репозиторий
 /// </summary>
 /// <param name="account"></param>
 public void Add(AccountViewModel account)
 {
     repository.Add(Convert(account));
 }
Esempio n. 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)
     };
 }
Esempio n. 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);
 }
Esempio n. 7
0
 public ActionResult New()
 {
     AccountViewModel model = new AccountViewModel();
     return View(model);
 }