Esempio n. 1
0
        public ActionResult ControllersGridViewUpdate([ModelBinder(typeof(DevExpressEditorsBinder))] Models.ControllersActions item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var res = unitOfWork.ControllersActionsRepo.Find(m => m.Id == item.Id);
                    foreach (var i in res.Users)
                    {
                        res.Users.Remove(i);
                    }
                    foreach (var i in res.UserId)
                    {
                        res.Users.Add(unitOfWork.UsersRepo.Find(m => m.Id == i));
                    }
                    res.Controller = item.Controller;
                    res.Action     = item.Action;
                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            var model = unitOfWork.ControllersActionsRepo.Get();

            return(PartialView("_ControllersGridView", model));
        }
Esempio n. 2
0
        public ActionResult ControllersGridViewAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Models.ControllersActions item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to insert the new item in your model

                    foreach (var i in item.UserId)
                    {
                        item.Users.Add(unitOfWork.UsersRepo.Find(m => m.Id == i));
                    }
                    unitOfWork.ControllersActionsRepo.Insert(item);
                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            var model = unitOfWork.ControllersActionsRepo.Get();

            return(PartialView("_ControllersGridView", model));
        }