Ejemplo n.º 1
0
        public ActionResult Save(RightViewModel rightViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //add
                    if (rightViewModel.RightId == 0 && rightViewModel.ActionName == "Add")
                    {
                        var model = new TblRight()
                        {
                            RightId       = rightViewModel.RightId,
                            RightName     = rightViewModel.RightName,
                            RightTitle    = rightViewModel.RightTitle,
                            Description   = rightViewModel.Description,
                            ApplicationId = rightViewModel.ApplicationId,
                            ModuleId      = rightViewModel.ModuleId
                        };

                        _rightRepository.Insert(model);
                    }
                    else if (rightViewModel.ActionName == "Edit") //edit
                    {
                        TblRight right = _rightRepository.GetById(rightViewModel.RightId);

                        if (right != null)
                        {
                            right.RightId     = rightViewModel.RightId;
                            right.RightName   = rightViewModel.RightName;
                            right.RightTitle  = rightViewModel.RightTitle;
                            right.Description = rightViewModel.Description;

                            right.ApplicationId = rightViewModel.ApplicationId;
                            right.ModuleId      = rightViewModel.ModuleId;

                            _rightRepository.Update(right);
                        }
                        else
                        {
                            return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, rightViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject())));
                        }
                    }

                    _rightRepository.Save();

                    return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, rightViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully.")));
                }

                return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, rightViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState))));
            }
            catch (Exception ex)
            {
                return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, rightViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageFormat(ex))));
            }
        }
Ejemplo n.º 2
0
        public async Task PullRight(int tblReposDetailId)
        {
            var tblLeft = tblLeftRepository.GetAll().FirstOrDefault(a => a.TblReposDetailId == tblReposDetailId);

            tblLeft.IsDeleted = true;
            if (tblRightRepository.GetAll().Any(a => a.TblReposDetailId == tblReposDetailId))
            {
                var tblRight = tblRightRepository.GetAll().FirstOrDefault(a => a.TblReposDetailId == tblReposDetailId);
                tblRight.IsDeleted = false;
            }
            else
            {
                var tblRight = new TblRight()
                {
                    TblReposDetailId = tblReposDetailId
                };
                await tblRightRepository.AddAsync(tblRight);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Role(string IdUsers, string id, FormCollection collection)
        {
            int ids   = int.Parse(collection["txtIdUser"]);
            var Right = db.TblRight.Where(p => p.IdUser == ids).ToList();

            for (int i = 0; i < Right.Count; i++)
            {
                int iddel = int.Parse(Right[i].Id.ToString());
                db.TblRight.Remove(db.TblRight.Find(iddel));
                db.SaveChanges();
            }
            foreach (string key in Request.Form.Keys)
            {
                var checkbox = "";
                if (key.StartsWith("chk_"))
                {
                    checkbox = Request.Form["" + key];
                    if (checkbox != "false")
                    {
                        string   Checkkey = key.Remove(0, 4);
                        string[] listkey  = Checkkey.Split('-');
                        int      idModule = int.Parse(listkey[0]);
                        int      Role     = int.Parse(listkey[1]);
                        int      IdUser   = int.Parse(listkey[2]);

                        TblRight TblRight = new TblRight();
                        TblRight.IdModule = idModule;
                        TblRight.Role     = Role;
                        TblRight.IdUser   = IdUser;
                        db.TblRight.Add(TblRight);
                        db.SaveChanges();
                    }
                }
            }
            Session["id"]       = "";
            Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã cấp quyền thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

            return(Redirect("/Users/Role?id=" + ids + ""));
        }