Exemplo n.º 1
0
        public ActionResult CreateOrEditPrivilege()
        {
            PrivilegeResponse _response = new PrivilegeResponse();

            if (Request.QueryString["id"] != null)
            {
                var request = new PrivilegeRequest
                {
                    Data = new PrivilegeModel
                    {
                        Id = long.Parse(Request.QueryString["id"].ToString())
                    }
                };

                PrivilegeResponse resp   = new PrivilegeHandler(_unitOfWork).GetDetail(request);
                PrivilegeModel    _model = resp.Entity;
                ViewBag.Response   = _response;
                ViewBag.Menu       = BindDropDownMenu();
                ViewBag.ActionType = ClinicEnums.Action.Edit;
                return(View(_model));
            }
            else
            {
                ViewBag.Response   = _response;
                ViewBag.Menu       = BindDropDownMenu();
                ViewBag.ActionType = ClinicEnums.Action.Add;
                return(View());
            }
        }
Exemplo n.º 2
0
        public ActionResult GetPrivilegeData()
        {
            var _draw          = Request.Form.GetValues("draw").FirstOrDefault();
            var _start         = Request.Form.GetValues("start").FirstOrDefault();
            var _length        = Request.Form.GetValues("length").FirstOrDefault();
            var _sortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var _sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
            var _searchValue   = Request.Form.GetValues("search[value]").FirstOrDefault();

            int _pageSize = _length != null?Convert.ToInt32(_length) : 0;

            int _skip = _start != null?Convert.ToInt32(_start) : 0;

            var request = new PrivilegeRequest
            {
                Draw          = _draw,
                SearchValue   = _searchValue,
                SortColumn    = _sortColumn,
                SortColumnDir = _sortColumnDir,
                PageSize      = _pageSize,
                Skip          = _skip
            };

            var response = new PrivilegeHandler(_unitOfWork).GetListData(request);

            return(Json(new { data = response.Data, recordsFiltered = response.RecordsFiltered, recordsTotal = response.RecordsTotal, draw = response.Draw }, JsonRequestBehavior.AllowGet));
        }
 public BaseResponse <PrivilegeResponse> CheckPrivilege([FromBody] PrivilegeRequest request)
 {
     return(BaseResponse <PrivilegeResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                privilegeService.CheckPrivilige(request)));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Validate request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void Validate(PrivilegeRequest request, out PrivilegeResponse response)
        {
            response = new PrivilegeResponse();

            if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString()))
            {
                ValidateForDelete(request, out response);
            }
            else
            {
                bool isHavePrivilege = true;

                if (request.Data.Privilige_Name == null || String.IsNullOrWhiteSpace(request.Data.Privilige_Name))
                {
                    errorFields.Add("Privilege Name");
                }

                if (errorFields.Any())
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields));
                }
                else if (request.Data.Privilige_Name.Length > 150)
                {
                    response.Status  = false;
                    response.Message = $"Maximum Character for Privilege Name is 150";
                }

                if (request.Data.Id == 0)
                {
                    isHavePrivilege = IsHaveAuthorization(ADD_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }
                else
                {
                    isHavePrivilege = IsHaveAuthorization(EDIT_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }

                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }

                if (response.Status)
                {
                    response = new PrivilegeHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
Exemplo n.º 5
0
        public JsonResult DeleteMasterPrivilege(int id)
        {
            PrivilegeResponse _response = new PrivilegeResponse();
            var request = new PrivilegeRequest
            {
                Data = new PrivilegeModel
                {
                    Id      = id,
                    Account = Session["UserLogon"] == null ? new AccountModel() : (AccountModel)Session["UserLogon"]
                },
                Action = ClinicEnums.Action.DELETE.ToString()
            };

            new PrivilegeValidator(_unitOfWork).Validate(request, out _response);

            return(Json(new { Status = _response.Status, Message = _response.Message }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        public async Task MakeCoursePrivilegeRequestAsync(PrivilegeRequestViewModel privilegeRequestVm, string userId)
        {
            var concatenatedAddress = ConcatGolfCourseAddressInformation(privilegeRequestVm.CourseAddress,
                                                                         privilegeRequestVm.City,
                                                                         privilegeRequestVm.StateCode, privilegeRequestVm.Zip);

            var courseRequest = new PrivilegeRequest
            {
                GolfCourseName    = privilegeRequestVm.CourseName,
                GolfCourseAddress = concatenatedAddress,
                Reason            = privilegeRequestVm.Reason,
                CoursePhoneNumber = privilegeRequestVm.CoursePhoneNumber,
                GolfCourseType    = privilegeRequestVm.CourseType,
                Verified          = false,
                UserId            = userId
            };
            await _privilegeRepository.AddCourseRequestAsync(courseRequest);
        }
Exemplo n.º 7
0
        private HttpResponseMessage GetResponse(HttpRequest request, String basePath)
        {
            string id = request.Headers["SessionID"];
            Guid   SessionID;

            try
            {
                SessionID = Guid.Parse(id);
            }
            catch
            {
                SessionID = new Guid();
            }

            var initialBody   = request.Body;
            var initialPath   = request.Path;
            var initialMethod = request.Method;

            PrivilegeRequest privilegeRequest = new PrivilegeRequest()
            {
                SessionID = SessionID,
                UrlPath   = GetPath(request),
                Method    = request.Method,
                Prefix    = basePath.Replace("/", "")
            };

            String privBody = JsonConvert.SerializeObject(privilegeRequest);

            byte[]       byteArray   = Encoding.UTF8.GetBytes(privBody);
            MemoryStream newPrivBody = new MemoryStream(byteArray);

            request.ContentType = "application/json";
            request.Body        = newPrivBody;
            request.Path        = new PathString("/");
            request.Method      = "POST";

            HttpResponseMessage authResponse = AuthenticationService.SendRequest(request);

            request.Body   = initialBody;
            request.Path   = initialPath;
            request.Method = initialMethod;

            return(authResponse);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Delete validation
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void ValidateForDelete(PrivilegeRequest request, out PrivilegeResponse response)
        {
            response = new PrivilegeResponse();

            if (request.Action == ClinicEnums.Action.DELETE.ToString())
            {
                bool isHavePrivilege = IsHaveAuthorization(DELETE_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }
            }

            if (response.Status)
            {
                response = new PrivilegeHandler(_unitOfWork).RemoveData(request);
            }
        }
Exemplo n.º 9
0
        public ActionResult CreateOrEditPrivilege(PrivilegeModel _model)
        {
            if (Session["UserLogon"] != null)
            {
                _model.Account = (AccountModel)Session["UserLogon"];
            }

            var request = new PrivilegeRequest
            {
                Data = _model
            };

            PrivilegeResponse _response = new PrivilegeResponse();

            new PrivilegeValidator(_unitOfWork).Validate(request, out _response);
            ViewBag.Response   = $"{_response.Status};{_response.Message}";
            ViewBag.Menu       = BindDropDownMenu();
            ViewBag.ActionType = request.Data.Id > 0 ? ClinicEnums.Action.Edit : ClinicEnums.Action.Add;

            return(View());
        }
Exemplo n.º 10
0
        public async Task <bool> EditPrivilegeRequest(PrivilegeRequest updatedPrivilegeRequest)
        {
            try
            {
                var privRequest = await _dataEntities.PrivilegeRequests.Where(gc => gc.Id.Equals(updatedPrivilegeRequest.Id)).FirstOrDefaultAsync();

                if (privRequest != null)
                {
                    privRequest = updatedPrivilegeRequest;

                    await _dataEntities.SaveChangesAsync();
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                e.GetBaseException();
                return(false);
            }
            return(true);
        }
        public PrivilegeResponse CheckPrivilige(PrivilegeRequest request)
        {
            Sessions sessions = dbContext.Sessions.Find(request.SessionID);

            if (sessions == null || !sessions.IsLogin)
            {
                return(new PrivilegeResponse()
                {
                    IsAllowed = false
                });
            }

            Users user = dbContext.Users.Find(sessions.UserId);

            if (user == null)
            {
                return(new PrivilegeResponse()
                {
                    IsAllowed = false
                });
            }

            List <Guid> userRoles = dbContext.UserRoles
                                    .Where(ur => ur.UserId.Equals(user.UserId))
                                    .Select(s => s.RoleId)
                                    .ToList();

            if (userRoles == null || userRoles.Count == 0)
            {
                return(new PrivilegeResponse()
                {
                    IsAllowed = false
                });
            }

            if (IsIncludeAdmin(userRoles))
            {
                return new PrivilegeResponse()
                       {
                           IsAllowed = true, UserID = user.UserId
                       }
            }
            ;

            List <Guid> rolePrivileges = dbContext.RolePrivileges
                                         .Where(rp => userRoles.Contains(rp.RoleId))
                                         .Select(rp => rp.PriviliegeId)
                                         .ToList();

            Privileges privileges = dbContext.Privileges
                                    .Where(p => p.Path.Equals(request.UrlPath) && p.Method.Equals(request.Method) &&
                                           p.Prefix.Equals(request.Prefix) && rolePrivileges.Contains(p.PrivilegeId))
                                    .FirstOrDefault();

            if (privileges == null)
            {
                return(new PrivilegeResponse()
                {
                    IsAllowed = false
                });
            }

            return(new PrivilegeResponse()
            {
                IsAllowed = true, UserID = user.UserId
            });
        }
Exemplo n.º 12
0
        public async Task <bool> RequestEditPrivilegeRequest(EditCourseViewModel editCourseVm, PrivilegeRequest privRequestInFocus)
        {
            if (privRequestInFocus.GolfCourseName != editCourseVm.NewCourseName)
            {
                privRequestInFocus.GolfCourseName = editCourseVm.NewCourseName;
            }
            if (privRequestInFocus.CoursePhoneNumber != editCourseVm.NewCoursePhone)
            {
                privRequestInFocus.CoursePhoneNumber = editCourseVm.NewCoursePhone;
            }
            if (privRequestInFocus.GolfCourseType != editCourseVm.NewCourseType)
            {
                privRequestInFocus.GolfCourseType = editCourseVm.NewCourseType;
            }

            var result = await _privilegeRepository.EditPrivilegeRequest(privRequestInFocus);

            return(result);
        }
Exemplo n.º 13
0
 public async Task AddCourseRequestAsync(PrivilegeRequest privilegeRequest)
 {
     _dataEntities.PrivilegeRequests.Add(privilegeRequest);
     await _dataEntities.SaveChangesAsync();
 }