示例#1
0
        public ServiceResult UpdatePageRole(Page_Role pPR)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.Page_Role.Where(w => w.Page_Role_ID == pPR.Page_Role_ID).FirstOrDefault();
                    if (current != null)
                    {
                        db.Entry(current).CurrentValues.SetValues(pPR);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.Page_Role
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.Page_Role,
                    Exception = ex
                });
            }
        }
示例#2
0
 public ServiceResult InsertPageRole(Page_Role pPR)
 {
     try
     {
         using (var db = new AgnosDBContext())
         {
             db.Page_Role.Add(pPR);
             db.SaveChanges();
             db.Entry(pPR).GetDatabaseValues();
             return(new ServiceResult()
             {
                 Code = ReturnCode.SUCCESS,
                 Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                 Field = Resource.Page_Role
             });
         }
     }
     catch (Exception ex)
     {
         return(new ServiceResult()
         {
             Code = ReturnCode.ERROR_INSERT,
             Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
             Field = Resource.Page_Role,
             Exception = ex
         });
     }
 }
示例#3
0
        public ActionResult RoleSetup(RoleSetupViewModel model)
        {
            var rService = new RoleService();

            if (model.tabAction == "pagerole")
            {
                if (model.Role_ID.HasValue && model.Page_ID.HasValue)
                {
                    var cri = new RoleCriteria();
                    cri.Role_ID = model.Role_ID;
                    cri.Page_ID = model.Page_ID;
                    var result = rService.GetPageRole(cri);
                    if (result.Code == ReturnCode.SUCCESS)
                    {
                        var dup  = new Page_Role();
                        var dups = result.Object as List <Page_Role>;
                        if (dups != null && dups.Count() != 0)
                        {
                            if (model.operation == Operation.C)
                            {
                                ModelState.AddModelError("Page_ID", Resource.The + " " + Resource.Page + " " + Resource.Field + " " + Resource.Is_Duplicated);
                            }
                            else if (model.operation == Operation.U)
                            {
                                dup = dups.FirstOrDefault();
                                if (dup.Page_Role_ID != model.Page_Role_ID)
                                {
                                    ModelState.AddModelError("Page_ID", Resource.The + " " + Resource.Page + " " + Resource.Field + " " + Resource.Is_Duplicated);
                                }
                            }
                        }
                    }
                }

                if (ModelState.IsValid)
                {
                    var prole = new Page_Role();
                    if (model.operation == Operation.U || model.operation == Operation.D)
                    {
                        var cri = new RoleCriteria();
                        cri.Page_Role_ID = model.Page_Role_ID;
                        var result = rService.GetPageRole(cri);
                        if (result.Code == ReturnCode.SUCCESS)
                        {
                            var proles = result.Object as List <Page_Role>;
                            if (proles != null && proles.Count() == 1)
                            {
                                prole = proles.FirstOrDefault();
                            }
                        }
                    }

                    if (model.operation != Operation.D)
                    {
                        prole.Role_ID = model.Role_ID;
                        prole.Page_ID = model.Page_ID;
                        prole.Modify  = (model.Modify.HasValue && model.Modify.Value ? true : false);
                        prole.View    = (model.View.HasValue && model.View.Value ? true : false);
                        prole.Close   = (model.Close.HasValue && model.Close.Value ? true : false);

                        if (prole.Modify.HasValue && prole.Modify.Value)
                        {
                            prole.View = true;
                        }

                        if (prole.Page_ID == 9 && prole.Role_ID == 5)
                        {
                            prole.View   = true;
                            prole.Modify = true;
                        }
                    }

                    if (model.operation == Operation.C)
                    {
                        model.result = rService.InsertPageRole(prole);
                    }

                    else if (model.operation == Operation.U)
                    {
                        model.result = rService.UpdatePageRole(prole);
                    }

                    else if (model.operation == Operation.D)
                    {
                        prole.Record_Status = Record_Status.Delete;
                        model.result        = rService.UpdatePageRole(prole);
                        if (model.result.Code == ReturnCode.SUCCESS)
                        {
                            model.result = new ServiceResult()
                            {
                                Code = ReturnCode.SUCCESS, Msg = Success.GetMessage(ReturnCode.SUCCESS_DELETE), Field = Resource.Page_Role
                            }
                        }
                        ;
                        else
                        {
                            model.result = new ServiceResult()
                            {
                                Code = ReturnCode.ERROR_DELETE, Msg = Error.GetMessage(ReturnCode.ERROR_DELETE), Field = Resource.Page_Role
                            }
                        };

                        return(RedirectToAction("RoleSetup", new AppRouteValueDictionary(model)));
                    }

                    if (model.result.Code == ReturnCode.SUCCESS)
                    {
                        return(RedirectToAction("RoleSetup", new AppRouteValueDictionary(model)));
                    }
                }
            }

            var cbService = new ComboService();

            model.cPageList = cbService.LstPage();
            model.cRoleList = cbService.LstRole(true);

            var rcri = new RoleCriteria();

            rcri.Role_ID = model.Role_ID;
            var result2 = rService.GetPageRole(rcri);

            if (result2.Code == ReturnCode.SUCCESS)
            {
                model.PageRoleList = result2.Object as List <Page_Role>;
            }
            return(View(model));
        }
    }