Beispiel #1
0
        public IActionResult Details(string id, EditPermissionRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(NotFoundView());
            }

            Result <PermissionViewModel> role = _permissionDataService.GetViewModel(id);

            if (role.Failure)
            {
                return(NotFoundView());
            }

            Result editResult = _permissionService.Edit(id, request);

            if (editResult.Failure)
            {
                ModelState.AddErrors(editResult.Errors);
                role.Value.StatusAlert = StatusAlertViewExtension.Get(editResult);

                return(View(role.Value));
            }

            role.Value.StatusAlert = StatusAlertViewExtension.Get("Permission updated");
            return(View(role.Value));
        }
Beispiel #2
0
        public JsonResult EditRolePermission(EditPermissionRequest reqeust)
        {
            if (string.IsNullOrEmpty(reqeust.Ids) || reqeust.RoleId == 0)
            {
                return(new NewJsonResult(new Baseresponse {
                    Success = 0
                }));
            }
            var rolemenulist = generateService.GetRoleMenuList(reqeust.HotelId, reqeust.RoleId);

            foreach (var item in rolemenulist)
            {
                generateService.DeleteRoleMenu(item.Id);
            }

            string[] ids = reqeust.Ids.Split(new char[] { ',' });
            foreach (var item in ids)
            {
                generateService.AddRoleMenu(new RoleMenuDto {
                    hotelid = reqeust.HotelId, Menu_id = int.Parse(item), Menu_pid = 0, RoleID = reqeust.RoleId
                });
            }

            return(new NewJsonResult(new Baseresponse {
                Success = 1
            }));
        }
        public Result Edit(string id, EditPermissionRequest editPermission)
        {
            BaseSpecification <PermissionEntity> baseSpecification = new BaseSpecification <PermissionEntity>();

            baseSpecification.AddFilter(x => x.Id == id);

            PermissionEntity permission = _permissionRepository.SingleOrDefault(baseSpecification);

            if (permission == null)
            {
                _logger.LogError($"No permission. PermissionId {id}");
                return(Result.Fail("no_permission", "No Permission"));
            }

            permission.Update(editPermission.Description);

            bool updateResult = _permissionRepository.Update(permission);

            if (!updateResult)
            {
                _logger.LogError($"Failed to update permission. PermissionId {id}");
                return(Result.Fail("failed_to_update_permission", "Failed to update permission"));
            }

            return(Result.Ok());
        }
Beispiel #4
0
        public GeneralResponse EditPermission(EditPermissionRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            //Permission permission = new Permission();
            //permission = _permissionRepository.FindBy(request.ID);

            //if (permission != null)
            //{
            //    try
            //    {
            //        permission.ModifiedDate = PersianDateTime.Now;
            //        permission.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
            //        if (request.Key != null)
            //            permission.Key = request.Key;
            //        if (request.Title != null)
            //            permission.Title = request.Title;

            //        if (permission.RowVersion != request.RowVersion)
            //        {
            //            response.hasCenter = false;
            //            response.ErrorMessages.Add("کارشناس محترم، یک کاربر همزمان با شما در حال ویرایش این رکورد است. بنابراین اطلاعات شما ذخیره نمی شود.");
            //            return response;
            //        }
            //        else
            //        {
            //            permission.RowVersion += 1;
            //        }

            //        if (permission.GetBrokenRules().Count() > 0)
            //        {
            //            response.hasCenter = false;
            //            foreach (BusinessRule businessRule in permission.GetBrokenRules())
            //            {
            //                response.ErrorMessages.Add(businessRule.Rule);
            //            }

            //            return response;
            //        }

            //        _permissionRepository.Save(permission);
            //        _uow.Commit();

            //        response.hasCenter = true;
            //    }
            //    catch (Exception ex)
            //    {
            //        response.hasCenter = false;
            //        response.ErrorMessages.Add(ex.Message);
            //    }
            //}
            //else
            //{
            //    response.hasCenter = false;
            //    response.ErrorMessages.Add("هیچ موردی جهت ویرایش وجود ندارد.");
            //}
            return(response);
        }
        public IActionResult EditInfo(Guid id, EditPermissionRequest request)
        {
            var command = new EditPermissionCommand(id, request.Label, request.Description,
                                                    request.Features, request.DeleteExistingFeatures);
            //_mapper.Map<EditPermissionCommand>(request);

            var result = _dispatcher.Dispatch(command);

            return(FromResult(result));
        }
Beispiel #6
0
        public ActionResult Permission_Edit(string id, [DataSourceRequest] DataSourceRequest request, PermissionView permission)
        {
            #region Check Access
            bool hasPermission = GetEmployee().IsGuaranteed("Permission_Update");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(Json(ModelState.ToDataSourceResult()));
            }
            #endregion

            EmployeeDetailView employeeDetailView = new EmployeeDetailView();
            employeeDetailView.EmployeeMainView = this.GetEmployeeView(id);

            if (permission != null && ModelState.IsValid)
            {
                try
                {
                    EditPermissionRequest editPermissionRequest = new EditPermissionRequest()
                    {
                        PermitKey  = permission.Key,
                        EmployeeID = Guid.Parse(id),
                        Guaranteed = permission.Guaranteed
                    };

                    GeneralResponse response = _employeeService.EditEmployee(editPermissionRequest);


                    if (response.hasError)
                    {
                        foreach (string error in response.ErrorMessages)
                        {
                            ModelState.AddModelError("", error);
                        }
                        return(View(employeeDetailView));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return(Json(ModelState.ToDataSourceResult()));
                }
            }

            return(Json(ModelState.ToDataSourceResult()));
        }
Beispiel #7
0
        /// <summary>
        /// ویرایش دسترسیهای یک کارمند
        /// </summary>
        public GeneralResponse EditEmployee(EditPermissionRequest request)
        {
            GeneralResponse response = new GeneralResponse();
            Employee        employee = new Employee();

            employee = _employeeRepository.FindBy(request.EmployeeID);

            if (employee != null)
            {
                try
                {
                    if (employee.Permissions.Where(s => s.PermitKey == request.PermitKey).FirstOrDefault() != null)
                    {
                        employee.Permissions.Where(s => s.PermitKey == request.PermitKey).FirstOrDefault().Guaranteed = request.Guaranteed;
                    }
                    else
                    {
                        IList <Permit>           permits     = employee.Permissions.ToList();
                        IEnumerable <Permission> permissions = _permissionRepository.FindAll();

                        permits.Add(new Permit(permissions.Where(s => s.Key == request.PermitKey).FirstOrDefault())
                        {
                            Guaranteed = request.Guaranteed
                        });
                        employee.Permissions = permits;
                    }
                    _employeeRepository.Save(employee);
                    _uow.Commit();
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }

            return(response);
        }