public ActionResult AccountManagment() { try { UserViewModel uvm = new UserViewModel(); if (FormsAuthentication.IsEnabled && FormsAuthentication.CookiesSupported && Request.Cookies[FormsAuthentication.FormsCookieName] != null) { string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; if (!String.IsNullOrEmpty(username)) { using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); Author au = ar.GetAuthorByEmail(username); if (au != null) { uvm.Cognome = au.Surname; uvm.Email = au.Email; uvm.Nascita = au.BirthDate.Value; uvm.Nome = au.Name; uvm.Password = au.Password; } else uvm.Message = "Si è verificato un problema durante il caricamento dati."; } } else uvm.Message = "Si è verificato un problema durante il caricamento dati."; return View(uvm); } else { uvm.Message = "Sessione utente probabilmente scaduta! Riprova a fare il login e assicurati di avere i cookie abilitati!"; return View(uvm); } } catch (Exception ex) { return Error(ex); } }
public ActionResult AccountManagment(UserViewModel model) { try { if (ModelState.IsValid) { if (FormsAuthentication.IsEnabled && FormsAuthentication.CookiesSupported) { string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; if (!String.IsNullOrEmpty(username)) { using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); Author au = ar.GetAuthorByEmail(username); au.ModifyAuthor(model.Nome, model.Cognome, model.Nascita, model.Email); ar.SaveOrUpdate(au); uow.Commit(); model.Message = "Modifica dei dati eseguita con successo!"; } } else model.Message = "Si è verificato un problema durante il recupero dei dati. Non è stato possibile apportare le modifiche richieste!"; } return View(model); } else return View(model); } catch (Exception ex) { return Error(ex); } }