Exemplo n.º 1
0
 // GET: User/UserEdit/5
 public ActionResult UserEdit(long? id)
 {
     if (!IsAuthorized())
         return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     User user = um.FindUser(id.Value);
     var model = new AdminEditUserViewModel
     {
         Id = user.Id,
         FirstName = user.FirstName,
         LastName = user.LastName,
         Name = user.Name,
         QuotaLimit = user.QuotaLimit / (1024 * 1024)
     };
     if (user == null)
     {
         return HttpNotFound();
     }
     return View(model);
 }
Exemplo n.º 2
0
        public ActionResult UserEdit(AdminEditUserViewModel model)
        {
            if (!IsAuthorized())
                return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
            if (ModelState.IsValid)
            {
                User u = um.FindUser(model.Id);
                u.Name = model.Name;
                u.FirstName = model.FirstName;
                u.LastName = model.LastName;
                u.QuotaLimit = model.QuotaLimit * 1024 * 1024;

                try
                {
                    um.Context.SaveChanges();
                }
                catch
                {
                    DisplayErrorMessage();
                    return View(model);
                }
                DisplaySuccessMessage("User details updated");
                return RedirectToAction("Index");
            }
            DisplayErrorMessage();
            return View(model);
        }