示例#1
0
        //[Authorize(Roles = "Admin")]
        public IActionResult Create()
        {
            try
            {
                var model = new RoleFormActionAssignmentsViewModel();
                ViewBag.Lists = GetItems();
                model.Items   = _systemFormRepository.GetAsQueryable()
                                .Select(x => new RoleFormActionAssignmentViewModel
                {
                    SystemFormId    = x.Id,
                    SystemFormTitle = x.Title
                }).ToList();

                return(View(model));
            }
            catch (Exception e)
            {
                Log.Error(e, e.Message);
                return(View("~/Views/Shared/Error.cshtml", new ErrorViewModel {
                    RequestId = e.Message
                }));
            }
        }
示例#2
0
        // [ValidateAntiForgeryToken]
        //[Authorize(Roles = "Admin")]
        public async Task <IActionResult> Create(RoleFormActionAssignmentsViewModel model)
        {
            try
            {
                ViewBag.Lists = GetItems();
                if (ModelState.IsValid)
                {
                    var roleActionAssignemtList = new List <RoleFormActionAssignment>();
                    foreach (var item in model.Items)
                    {
                        var systemAction = SystemAction.None;

                        if (item.CanCreate)
                        {
                            systemAction = systemAction | SystemAction.Create;
                        }
                        if (item.CanRead)
                        {
                            systemAction = systemAction | SystemAction.Read;
                        }
                        if (item.CanUpdate)
                        {
                            systemAction = systemAction | SystemAction.Update;
                        }
                        if (item.CanDelete)
                        {
                            systemAction = systemAction | SystemAction.Delete;
                        }

                        if (systemAction != SystemAction.None)
                        {
                            var assignment = new RoleFormActionAssignment
                            {
                                SystemFormId = item.SystemFormId,
                                SystemAction = systemAction,
                                RoleId       = model.RoleId
                            };
                            roleActionAssignemtList.Add(assignment);
                        }
                    }
                    await _roleFormActionAssignmentRepository.InsertAllAsync(roleActionAssignemtList);

                    if (Request.Form.Keys.Contains("SaveAndReturn"))
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("Edit", new { id = model.RoleId }));
                    }
                }
                return(View(model));
            }
            catch (Exception e)
            {
                Log.Error(e, e.Message);
                return(View("~/Views/Shared/Error.cshtml", new ErrorViewModel {
                    RequestId = e.Message
                }));
            }
        }
示例#3
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                //var model = new RoleFormActionAssignmentsViewModel();
                //model.RoleId = id;
                //var currRoles = _roleFormActionAssignmentRepository.GetAsQueryable(x => x.RoleId == id).Join(_systemFormRepository.GetAsQueryable(), a => a.SystemFormId, b => b.Id, (a, b) => new { allRoles = a, systemForms = b });

                //model.Items = currRoles.Select(x => new RoleFormActionAssignmentViewModel
                //{
                //    SystemFormId = x.systemForms.Id,
                //    SystemFormTitle = x.systemForms.Title,
                //    CanCreate = (x.allRoles.SystemAction & SystemAction.Create) != 0,
                //    CanRead = (x.allRoles.SystemAction & SystemAction.Read) != 0,
                //    CanUpdate = (x.allRoles.SystemAction & SystemAction.Update) != 0,
                //    CanDelete = (x.allRoles.SystemAction & SystemAction.Delete) != 0,
                //    SystemAction = x.allRoles.SystemAction
                //}).ToList();
                //return View(model);


                //var model = new RoleFormActionAssignmentsViewModel();
                //model.RoleId = id;
                //var currRoles = _systemFormRepository.GetAsQueryable().GroupJoin(_roleFormActionAssignmentRepository.GetAsQueryable(), a => a.Id, b => b.SystemFormId, (a, b) => new { systemForms= a, allRoles = b }).SelectMany(
                //  sysForm => sysForm.allRoles.DefaultIfEmpty(),
                //  (x, y) => new { Forms= x.systemForms, rols = y }); ;

                //model.Items = currRoles.Select(x => new RoleFormActionAssignmentViewModel
                //{
                //    SystemFormId = x.Forms.Id,
                //    SystemFormTitle = x.Forms.Title,
                //    CanCreate = (x.rols.SystemAction & SystemAction.Create) != 0,
                //    CanRead = (x.rols.SystemAction & SystemAction.Read) != 0,
                //    CanUpdate = (x.rols.SystemAction & SystemAction.Update) != 0,
                //    CanDelete = (x.rols.SystemAction & SystemAction.Delete) != 0,
                //    SystemAction = x.rols.SystemAction
                //}).ToList(); ;
                //return View(model);

                var resultFormActionAssignments = await _roleFormActionAssignmentRepository.GetAsync(x => x.RoleId == id);


                var roleFormActionAssignments = resultFormActionAssignments.Select(x => new
                {
                    x.SystemFormId,
                    x.SystemAction
                }).ToList();

                var model = new RoleFormActionAssignmentsViewModel();
                model.RoleId = id;
                var sysFormList = await _systemFormRepository.GetAsync();

                model.Items = sysFormList
                              .Select(x => new RoleFormActionAssignmentViewModel
                {
                    SystemFormId    = x.Id,
                    SystemFormTitle = x.Title,
                    CanCreate       = (roleFormActionAssignments.Where(r => r.SystemFormId == x.Id).Select(r => r.SystemAction).FirstOrDefault() & SystemAction.Create) != 0,
                    CanRead         = (roleFormActionAssignments.Where(r => r.SystemFormId == x.Id).Select(r => r.SystemAction).FirstOrDefault() & SystemAction.Read) != 0,
                    CanUpdate       = (roleFormActionAssignments.Where(r => r.SystemFormId == x.Id).Select(r => r.SystemAction).FirstOrDefault() & SystemAction.Update) != 0,
                    CanDelete       = (roleFormActionAssignments.Where(r => r.SystemFormId == x.Id).Select(r => r.SystemAction).FirstOrDefault() & SystemAction.Delete) != 0
                }).ToList();

                // return RedirectToAction("Index");

                return(View(model));
            }
            catch (Exception e)
            {
                Log.Error(e, e.Message);
                return(View("~/Views/Shared/Error.cshtml", new ErrorViewModel {
                    RequestId = e.Message
                }));
            }
        }