示例#1
0
 public static ServiceRequest MapDtoToServiceRequest(IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> src)
 {
     if (src == null)
     {
         return(null);
     }
     return(new ServiceRequest
     {
         Id = src.Id,
         Name = src.Name,
         Action = src.Action,
         State = src.State,
         ApprovedDate = src.ApprovedDate,
         ApproverUserId = src.ApproverUserId,
         Comments = src.Comments,
         CreationDate = src.CreationDate,
         Officeuse = src.Officeuse,
         RequestedByUserId = src.RequestedByUserId,
         RequestedForGuids = src.RequestedForGuids,
         RequestedByGuid = src.RequestedByGuid,
         SubmissionDate = src.SubmissionDate,
         RequestedForDate = src.RequestedForDate,
         ServiceOptionId = src.ServiceOptionId,
         DepartmentId = src.DepartmentId,
         CancelledDate = src.CancelledDate,
         DeniedDate = src.DeniedDate,
         FulfilledDate = src.FulfilledDate,
         FinalMonthlyPrice = src.FinalMonthlyPrice,
         FinalUpfrontPrice = src.FinalUpfrontPrice
     });
 }
示例#2
0
        protected override bool UserHasPermissionToModify(int performingUserId, IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> request, EntityModification modification, out object permission)
        {
            permission = ServiceRequestSubmission.CanSubmitRequests;
            switch (modification)
            {
            case EntityModification.Create:
                return(_userManager.UserHasPermission(performingUserId, (ServiceRequestSubmission)permission));

            case EntityModification.Update:
                return(_requestManager.UserCanEditRequest(performingUserId, request.Id));

            case EntityModification.Delete:
                return(_userManager.UserHasPermission(performingUserId, (ServiceRequestSubmission)permission));
            }
            return(false);
        }
示例#3
0
        /// <summary>
        /// Creates a Request object copy from a IServiceRequestDto
        /// </summary>
        /// <param name="src"></param>
        internal Request(IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> src)
        {
            Id                = src.Id;
            Name              = src.Name;
            Action            = src.Action;
            State             = src.State;
            ApprovedDate      = src.ApprovedDate;
            ApproverUserId    = src.ApproverUserId;
            Comments          = src.Comments;
            CreationDate      = src.CreationDate;
            Officeuse         = src.Officeuse;
            RequestedByUserId = src.RequestedByUserId;
            RequestedForGuids = src.RequestedForGuids;
            RequestedByGuid   = src.RequestedByGuid;
            SubmissionDate    = src.SubmissionDate;
            RequestedForDate  = src.RequestedForDate;
            ServiceOptionId   = src.ServiceOptionId;
            DepartmentId      = src.DepartmentId;
            CancelledDate     = src.CancelledDate;
            DeniedDate        = src.DeniedDate;
            FulfilledDate     = src.FulfilledDate;
            FinalMonthlyPrice = src.FinalMonthlyPrice;
            FinalUpfrontPrice = src.FinalUpfrontPrice;

            ServiceRequestOptions = new List <ServiceRequestOptionDto>();
            foreach (var sro in src.ServiceRequestOptions)
            {
                ServiceRequestOptions.Add((ServiceRequestOptionDto)sro);
            }

            ServiceRequestUserInputs = new List <ServiceRequestUserInputDto>();
            foreach (var sro in src.ServiceRequestUserInputs)
            {
                ServiceRequestUserInputs.Add((ServiceRequestUserInputDto)sro);
            }
        }
示例#4
0
        /// <summary>
        /// Changes the state of a service request to Submitted if the action is possible.
        /// </summary>
        /// <param name="userId">ID of user Submitting the request</param>
        /// <param name="requestId">ID of Service Request to Submit</param>
        /// <returns>Service Request after Submition is attempted</returns>
        public IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> SubmitRequest(int userId, int requestId)
        {
            IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> request = RequestFromId(requestId);

            if (request.State != ServiceRequestState.Incomplete)
            {
                throw new ServiceRequestStateException(
                          string.Format("Cannot change the state of a Service Request to \"{0}\". " +
                                        "Service Request is in the \"{1}\" state and must be in the " +
                                        "\"{2}\" state to perform this action.",
                                        ServiceRequestState.Submitted, request.State, ServiceRequestState.Incomplete));
            }

            if (UserCanSubmitRequest(userId, requestId))
            {
                using (var context = new PrometheusContext())
                {
                    var requestEntity = context.ServiceRequests.Find(requestId);

                    //Change state of the entity
                    requestEntity.State          = ServiceRequestState.Submitted;
                    requestEntity.SubmissionDate = DateTime.UtcNow;

                    //Save
                    context.Entry(requestEntity).State = EntityState.Modified;
                    context.SaveChanges(userId);
                    request = ManualMapper.MapServiceRequestToDto(requestEntity);
                }
            }

            return(request);
        }
示例#5
0
        /// <summary>
        /// Changes the state of a service request to the state provided if the action is possible.
        /// </summary>
        /// <param name="userId">ID of user performing the state change</param>
        /// <param name="requestId">ID of Service Request to change the state of</param>
        /// <param name="state">State to change the Service Request to</param>
        /// <param name="comments">Optional: Comments tied to the state change if applicable</param>
        /// <returns>Service Request after state change is attempted</returns>
        public IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> ChangeRequestState(int userId, int requestId, ServiceRequestState state, string comments = null)
        {
            IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> request = RequestFromId(requestId);

            switch (state)
            {
            case ServiceRequestState.Incomplete:
                throw new ServiceRequestStateException("Cannot change the state of a Service Request to Incomplete.");

            case ServiceRequestState.Submitted:
                return(SubmitRequest(userId, requestId));

            case ServiceRequestState.Approved:
            case ServiceRequestState.Denied:
                ApprovalResult approval = state == ServiceRequestState.Approved ? ApprovalResult.Approved : ApprovalResult.Denied;
                return(ApproveRequest(userId, requestId, approval, comments));

            case ServiceRequestState.Cancelled:
                return(CancelRequest(userId, requestId, comments));

            case ServiceRequestState.Fulfilled:
                return(FulfillRequest(userId, requestId, comments));
            }
            return(request);
        }
示例#6
0
        /// <summary>
        /// Changes the state of a service request to the result of the Approval if the action is possible.
        /// </summary>
        /// <param name="userId">ID of user Approving the request</param>
        /// <param name="requestId">ID of Service Request to Approve</param>
        /// <param name="approvalResult">Result of the approval transaction (approved or denied)</param>
        /// <param name="comments">Optional: Comments tied to the Approval if applicable</param>
        /// <returns>Service Request after Approval is attempted</returns>
        public IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> ApproveRequest(int userId, int requestId, ApprovalResult approvalResult, string comments)
        {
            IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> request = RequestFromId(requestId);

            if (request.State != ServiceRequestState.Submitted)
            {
                throw new ServiceRequestStateException(
                          string.Format("Cannot change the state of a Service Request to \"{0}\". " +
                                        "Service Request is in the \"{1}\" state and must be in the " +
                                        "\"{2}\" state to perform this action.",
                                        approvalResult, request.State, ServiceRequestState.Submitted));
            }

            if (UserCanApproveRequest(userId, requestId))
            {
                using (var context = new PrometheusContext())
                {
                    //Build and save approval transaction
                    Approval approval = new Approval()
                    {
                        ApproverId       = userId,
                        Comments         = comments,
                        RequestorId      = request.RequestedByUserId,
                        ServiceRequestId = request.Id,
                        Result           = approvalResult
                    };
                    context.Approvals.Add(approval);
                    context.SaveChanges(userId);

                    //Change state of the entity
                    var requestEntity = context.ServiceRequests.Find(requestId);
                    ClearTemporaryFields(requestEntity);

                    //Approve or deny
                    if (approvalResult == ApprovalResult.Approved)
                    {
                        requestEntity.State        = ServiceRequestState.Approved;
                        requestEntity.ApprovedDate = DateTime.UtcNow;
                    }
                    else
                    {
                        requestEntity.State      = ServiceRequestState.Denied;
                        requestEntity.DeniedDate = DateTime.UtcNow;
                    }

                    requestEntity.FinalUpfrontPrice = requestEntity.UpfrontPrice;
                    requestEntity.FinalMonthlyPrice = requestEntity.MonthlyPrice;

                    context.Entry(requestEntity).State = EntityState.Modified;
                    context.SaveChanges(userId);
                    request = ManualMapper.MapServiceRequestToDto(requestEntity);
                }
            }

            return(request);
        }
示例#7
0
 protected override IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> Delete(int performingUserId, IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> serviceRequestDto)
 {
     using (var context = new PrometheusContext())
     {
         var toDelete = context.ServiceRequests.Find(serviceRequestDto.Id);
         context.ServiceRequests.Remove(toDelete);
         context.SaveChanges(performingUserId);
     }
     return(null);
 }
示例#8
0
 protected override IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> Update(int performingUserId, IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> serviceRequestDto)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ServiceRequests.Any(x => x.Id == serviceRequestDto.Id))
         {
             throw new InvalidOperationException(string.Format("Service Request with ID {0} cannot be updated since it does not exist.", serviceRequestDto.Id));
         }
         var updated = ManualMapper.MapDtoToServiceRequest(serviceRequestDto);
         context.ServiceRequests.Attach(updated);
         context.Entry(updated).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceRequestToDto(updated));
     }
 }
示例#9
0
 protected override IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> Create(int performingUserId, IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> serviceRequestDto)
 {
     using (var context = new PrometheusContext())
     {
         var serviceRequest = context.ServiceRequests.Find(serviceRequestDto.Id);
         if (serviceRequest != null)
         {
             throw new InvalidOperationException(string.Format("Service Request with ID {0} already exists.", serviceRequestDto.Id));
         }
         var saved = context.ServiceRequests.Add(ManualMapper.MapDtoToServiceRequest(serviceRequestDto));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapServiceRequestToDto(saved));
     }
 }
示例#10
0
 /// <summary>
 /// Modifies the service request in the database
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <param name="serviceRequest"></param>
 /// <param name="modification">Type of modification to make</param>
 /// <returns>Modified Service Request</returns>
 public IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> ModifyServiceRequest(int performingUserId, IServiceRequestDto <IServiceRequestOptionDto, IServiceRequestUserInputDto> serviceRequest, EntityModification modification)
 {
     return(base.ModifyEntity(performingUserId, serviceRequest, modification));
 }