예제 #1
0
 public static List <VoluntaryPlanWaiverRequestDto> SubmitRequest(VoluntaryPlanWaiverRequestDto VPRequestForm)
 {
     ExecuteSubmitRequestRules(VPRequestForm);
     if (Context.ValidationMessages.Count(ValidationMessageSeverity.Error) == 0)
     {
         using (DbContext context = new DbContext())
         {
             VPRequestForm.VoluntaryPlanWaiverRequestTypes.RemoveAll(r => r.LeaveTypeCode == null);
             VoluntaryPlanWaiverRequest.FromDto(context, VPRequestForm);
             context.SaveChanges();
         }
     }
     else
     {
         Context.ValidationMessages.ThrowCheck(ValidationMessageSeverity.Error);
     }
     return(GetRequestColl(VPRequestForm.EmployerId));
 }
예제 #2
0
        public static List <VPRequestViewModel> SubmitRequest(VPRequestForm VPRequestForm)
        {
            #region Commented
            //VoluntaryPlanWaiverRequestDto obj = new VoluntaryPlanWaiverRequestDto();
            //obj.EmployerId = 1;
            //obj.StartDate = DateTime.Now;
            //obj.EndDate = DateTime.Now;
            //obj.IsVoluntaryPlanWaiverRequestAcknowledged = true;
            //obj.VoluntaryPlanWaiverRequestTypes.Add(new VoluntaryPlanWaiverRequestTypeDto()
            //{
            //	LeaveTypeCode = LookupTable_WaiverLeaveType.Medical,
            //	PercentagePaid = 2,
            //	DurationInWeeksCode = LookupTable_WaiverWeeksAvailable._1Week
            //});
            //obj.VoluntaryPlanWaiverRequestTypes.Add(new VoluntaryPlanWaiverRequestTypeDto()
            //{
            //	LeaveTypeCode = LookupTable_WaiverLeaveType.Medical,
            //	PercentagePaid = 1,
            //	DurationInWeeksCode = LookupTable_WaiverWeeksAvailable._4Weeks
            //});

            //VPRequestForm = new VPRequestForm()
            //{
            //	EmployerId = 1,
            //	StartDate = DateTime.Now,
            //	EndDate = DateTime.Now,
            //	IsAcknolwedged = true,
            //	RequestType = new List<VoluntaryPlanWaiverRequestTypeDto>() {
            //		new VoluntaryPlanWaiverRequestTypeDto()
            //		{
            //			 LeaveTypeCode = LookupTable_WaiverLeaveType.Medical,
            //			  PercentagePaid = 2,
            //			  DurationInWeeksCode = LookupTable_WaiverWeeksAvailable._1Week
            //		},
            //		new VoluntaryPlanWaiverRequestTypeDto()
            //		{
            //			 LeaveTypeCode = LookupTable_WaiverLeaveType.Medical,
            //			  PercentagePaid = 1,
            //			  DurationInWeeksCode = LookupTable_WaiverWeeksAvailable._1Week
            //		}
            //	},
            //	Document = new List<DocumentDto>() {
            //		 new DocumentDto(){
            //			  DocumentDescription="Doc Description",
            //			  DocumentName ="DJ.pdf"
            //		 }
            //	}

            //};
            #endregion

            ExecuteSubmitRequestRules(VPRequestForm);
            if (Context.ValidationMessages.Count(ValidationMessageSeverity.Error) == 0)
            {
                using (DbContext context = new DbContext())
                {
                    FormDto FormReq = new FormDto()
                    {
                        FormTypeCode = LookupTable_FormType.VPWaiverForm,
                        StatusCode   = LookupTable_WaiverRequestStatus.SavedasDraft
                    };
                    Form.FromDto(context, FormReq);

                    VoluntaryPlanWaiverRequestDto VPWReq = new VoluntaryPlanWaiverRequestDto()
                    {
                        EmployerId = VPRequestForm.EmployerId,
                        StartDate  = VPRequestForm.StartDate,
                        EndDate    = VPRequestForm.EndDate,
                        IsVoluntaryPlanWaiverRequestAcknowledged = VPRequestForm.IsAcknolwedged
                    };
                    VoluntaryPlanWaiverRequest.FromDto(context, VPWReq);


                    VPRequestForm.RequestType.RemoveAll(p => string.IsNullOrWhiteSpace(p.LeaveTypeCode));
                    foreach (var requestType in VPRequestForm.RequestType)
                    {
                        VoluntaryPlanWaiverRequestType VPWReqType = new VoluntaryPlanWaiverRequestType()
                        {
                            LeaveTypeCode       = requestType.LeaveTypeCode,
                            PercentagePaid      = requestType.PercentagePaid,
                            DurationInWeeksCode = requestType.DurationInWeeksCode
                        };
                        context.VoluntaryPlanWaiverRequestTypes.Add(VPWReqType);
                    }

                    if (VPRequestForm.Document != null)
                    {
                        foreach (var docItem in VPRequestForm.Document)
                        {
                            Document doc = new Document()
                            {
                                DocumentName        = docItem.DocumentName,
                                ExternalDocumentId  = Guid.NewGuid(),
                                DocumentDescription = docItem.DocumentDescription
                            };
                            context.Documents.Add(doc);
                            context.FormAttachments.Add(new FormAttachment());
                        }
                    }

                    context.SaveChanges();
                }
            }
            else
            {
                Context.ValidationMessages.ThrowCheck(ValidationMessageSeverity.Error);
            }
            return(GetRequestColl(VPRequestForm.EmployerId));
        }