public ActionResult Create(Uzivatel collection) { try { if (ModelState.IsValid) { var dao = new UzivatelDao(); collection.WindowsId = collection.WindowsId.ToUpper(); collection.Id = (int)dao.Create(collection); if (collection.Role.Id > 0) { var permDao = new PermissionDao(); permDao.Create(new Permission() { Role = collection.Role, WindowsId = collection.WindowsId }); } TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserAdded; return(RedirectToAction("Index")); } else { TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje"; } } catch { TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje"; } return(View(collection)); }
public ActionResult Edit(int id, Uzivatel collection) { try { if (ModelState.IsValid) { var dao = new UzivatelDao(); collection.WindowsId = collection.WindowsId.ToUpper(); dao.Update(collection); var permDao = new PermissionDao(); var permItem = permDao.GetByUser(collection); if (collection.Role.Id == 0) { if (permItem != null) { permDao.Delete(permItem); } } else { if (permItem == null) { permDao.Create(new Permission() { Role = collection.Role, WindowsId = collection.WindowsId }); } else if (permItem.Role.Id != collection.Role.Id) { permItem.Role.Id = collection.Role.Id; permDao.Update(permItem); } } TempData[MessagesHelper.Success] = Resources.UzivatelTexts.UserUpdated; return(RedirectToAction("Index")); } else { TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje"; } } catch { TempData[MessagesHelper.Warning] = "Zkontrolujte zadané údaje"; } return(View(collection)); }