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