/// <summary> /// /// </summary> /// <param name="VPRequestForm"></param> /// <returns></returns> internal static VoluntaryPlanWaiverRequestDto SetLeaveType(VoluntaryPlanWaiverRequestDto voluntaryPlanWaiverRequestDto) { foreach (var waiverLeaveType in LookupTable.WaiverLeaveType) { voluntaryPlanWaiverRequestDto.VoluntaryPlanWaiverRequestTypes.Add(new VoluntaryPlanWaiverRequestTypeDto()); } return(voluntaryPlanWaiverRequestDto); }
public static VoluntaryPlanWaiverRequestDto SetData() { VoluntaryPlanWaiverRequestDto voluntaryPlanWaiverRequestDto = new VoluntaryPlanWaiverRequestDto { StartDate = DateTime.Now.Date, EndDate = new DateTime(DateTime.Now.Year, 12, 31) }; return(SetLeaveType(voluntaryPlanWaiverRequestDto)); }
public static VoluntaryPlanWaiverRequestDto GetRequest(VoluntaryPlanWaiverRequestDto VoluntaryPlanWaiverRequestDto) { using (DbContext context = new DbContext()) { var record = (from vpwr in context.VoluntaryPlanWaiverRequests.Include("VoluntaryPlanWaiverRequestTypes").Include("Form.FormAttachments.Document") where vpwr.FormId == VoluntaryPlanWaiverRequestDto.FormId select vpwr).FirstOrDefault(); return(record.ToDtoDeep(context)); } }
/// <summary>Convert from VoluntaryPlanWaiverRequest entity to DTO w/o checking entity state or entity navigation</summary> /// <param name="dto">DTO to use if already created instead of creating new one (can be inherited class instead as opposed to base class)</param> /// <returns>Resultant VoluntaryPlanWaiverRequest DTO</returns> public VoluntaryPlanWaiverRequestDto ToDto(VoluntaryPlanWaiverRequestDto dto = null) { dto = dto ?? new VoluntaryPlanWaiverRequestDto(); base.ToDto(dto); dto.EmployerId = EmployerId; dto.EndDate = EndDate; dto.IsVoluntaryPlanWaiverRequestAcknowledged = IsVoluntaryPlanWaiverRequestAcknowledged; dto.StartDate = StartDate; return(dto); }
internal static void ExecuteSubmitRequestRules(VoluntaryPlanWaiverRequestDto VPRequestForm) { if (VPRequestForm.StartDate.Date >= DateTime.Today.Date) { Context.ValidationMessages.AddError("Start Date cannot be before today."); } if (VPRequestForm.EndDate.Date < VPRequestForm.StartDate.Date) { Context.ValidationMessages.AddError("End date cannot be before Start date."); } if (VPRequestForm.EndDate.Date > VPRequestForm.StartDate.Date.AddYears(1).AddDays(-1)) { Context.ValidationMessages.AddError("End Date cannot be more than 1 year after the Start Date"); } if (!VPRequestForm.IsVoluntaryPlanWaiverRequestAcknowledged) { Context.ValidationMessages.AddError("You must agree to the T&C to submit your request"); } bool leaveTypeChecked = false; foreach (var item in VPRequestForm.VoluntaryPlanWaiverRequestTypes) { if (!string.IsNullOrWhiteSpace(item.LeaveTypeCode)) { leaveTypeChecked = true; if (string.IsNullOrWhiteSpace(item.DurationInWeeksCode) && (item.PercentagePaid <= 0)) { Context.ValidationMessages.AddError("Weeks Available annually and Percentage of Wages Paid are required fields for the checked leave type"); break; } if (string.IsNullOrWhiteSpace(item.DurationInWeeksCode) && (item.PercentagePaid >= 0)) { Context.ValidationMessages.AddError("Please select Weeks Available annually for the checked leave type"); } if (!string.IsNullOrWhiteSpace(item.DurationInWeeksCode) && (item.PercentagePaid <= 0)) { Context.ValidationMessages.AddError("Please provide Percentage of wages paid for the checked leave type"); break; } } } if (!leaveTypeChecked) { Context.ValidationMessages.AddError("Atleast one Leave Type should be selected"); //Available annually and Percentage of Wages Paid in the type of leave available section should be provided } }
protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, VoluntaryPlanWaiverRequestDto dto, VoluntaryPlanWaiverRequest entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities) { entity.EmployerId = dto.EmployerId; entity.EndDate = dto.EndDate; entity.IsVoluntaryPlanWaiverRequestAcknowledged = dto.IsVoluntaryPlanWaiverRequestAcknowledged; entity.StartDate = dto.StartDate; entity.Employer = (dto.Employer == null) ? null : Employer.FromDto(dbContext, dto.Employer, dtoEntities); if (dto.VoluntaryPlanWaiverRequestTypes != null) { foreach (VoluntaryPlanWaiverRequestTypeDto voluntaryPlanWaiverRequestType in dto.VoluntaryPlanWaiverRequestTypes) { entity.VoluntaryPlanWaiverRequestTypes.Add(DbEntities.VoluntaryPlanWaiverRequestType.FromDto(dbContext, voluntaryPlanWaiverRequestType, dtoEntities)); } } }
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)); }
/// <summary>Convert from VoluntaryPlanWaiverRequest entity to DTO w/o checking entity state or entity navigation</summary> /// <param name="dto">DTO to use if already created instead of creating new one (can be inherited class instead as opposed to base class)</param> /// <returns>Resultant VoluntaryPlanWaiverRequest DTO</returns> public VoluntaryPlanWaiverRequestDto ToDto(VoluntaryPlanWaiverRequestDto dto = null) { dto = dto ?? new VoluntaryPlanWaiverRequestDto(); dto.IsNew = false; dto.CreateDateTime = CreateDateTime; dto.CreateUserId = CreateUserId; dto.EmployerId = EmployerId; dto.EndDate = EndDate; dto.FormId = FormId; dto.IsVoluntaryPlanWaiverRequestAcknowledged = IsVoluntaryPlanWaiverRequestAcknowledged; dto.StartDate = StartDate; dto.UpdateDateTime = UpdateDateTime; dto.UpdateNumber = UpdateNumber; dto.UpdateProcess = UpdateProcess; dto.UpdateUserId = UpdateUserId; dto.VoluntaryPlanWaiverRequestId = VoluntaryPlanWaiverRequestId; return(dto); }
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)); }
/// <summary>Convert from VoluntaryPlanWaiverRequest DTO to entity</summary> /// <param name="dbContext">DB Context to use for attaching entity</param> /// <param name="dto">DTO to convert from</param> /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param> /// <returns>Resultant VoluntaryPlanWaiverRequest entity</returns> public static VoluntaryPlanWaiverRequest FromDto(FACTS.Framework.DAL.DbContext dbContext, VoluntaryPlanWaiverRequestDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null) { dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>(); if (dtoEntities.ContainsKey(dto)) { return((VoluntaryPlanWaiverRequest)dtoEntities[dto]); } VoluntaryPlanWaiverRequest entity = new VoluntaryPlanWaiverRequest(); dtoEntities.Add(dto, entity); entity.CreateDateTime = dto.CreateDateTime; entity.CreateUserId = dto.CreateUserId; entity.EmployerId = dto.EmployerId; entity.EndDate = dto.EndDate; entity.FormId = dto.FormId; entity.IsVoluntaryPlanWaiverRequestAcknowledged = dto.IsVoluntaryPlanWaiverRequestAcknowledged; entity.StartDate = dto.StartDate; entity.UpdateDateTime = dto.UpdateDateTime; entity.UpdateNumber = dto.UpdateNumber; entity.UpdateProcess = dto.UpdateProcess; entity.UpdateUserId = dto.UpdateUserId; entity.VoluntaryPlanWaiverRequestId = dto.VoluntaryPlanWaiverRequestId; entity.Employer = (dto.Employer == null) ? null : Employer.FromDto(dbContext, dto.Employer, dtoEntities); entity.Form = (dto.Form == null) ? null : Form.FromDto(dbContext, dto.Form, dtoEntities); if (dto.VoluntaryPlanWaiverRequestTypes != null) { foreach (VoluntaryPlanWaiverRequestTypeDto voluntaryPlanWaiverRequestType in dto.VoluntaryPlanWaiverRequestTypes) { entity.VoluntaryPlanWaiverRequestTypes.Add(DbEntities.VoluntaryPlanWaiverRequestType.FromDto(dbContext, voluntaryPlanWaiverRequestType, dtoEntities)); } } if (dbContext != null) { dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified)); } return(entity); }
/// <summary>Convert from VoluntaryPlanWaiverRequest entity to DTO</summary> /// <param name="dbContext">DB Context to use for setting DTO state</param> /// <param name="dto">DTO to use if already created instead of creating new one (can be inherited class instead as opposed to base class)</param> /// <param name="entityDtos">Used internally to track which entities have been converted to DTO's already (to avoid re-converting when circularly referenced)</param> /// <returns>Resultant VoluntaryPlanWaiverRequest DTO</returns> public VoluntaryPlanWaiverRequestDto ToDtoDeep(FACTS.Framework.DAL.DbContext dbContext, VoluntaryPlanWaiverRequestDto dto = null, Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto> entityDtos = null) { entityDtos = entityDtos ?? new Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto>(); if (entityDtos.ContainsKey(this)) { return((VoluntaryPlanWaiverRequestDto)entityDtos[this]); } dto = ToDto(dto); entityDtos.Add(this, dto); System.Data.Entity.Infrastructure.DbEntityEntry <VoluntaryPlanWaiverRequest> entry = dbContext?.Entry(this); dto.IsNew = (entry?.State == EntityState.Added); dto.IsDeleted = (entry?.State == EntityState.Deleted); if (entry?.Reference(x => x.Employer)?.IsLoaded == true) { dto.Employer = Employer?.ToDtoDeep(dbContext, entityDtos: entityDtos); } if (entry?.Reference(x => x.Form)?.IsLoaded == true) { dto.Form = Form?.ToDtoDeep(dbContext, entityDtos: entityDtos); } if (entry?.Collection(x => x.VoluntaryPlanWaiverRequestTypes)?.IsLoaded == true) { foreach (VoluntaryPlanWaiverRequestType voluntaryPlanWaiverRequestType in VoluntaryPlanWaiverRequestTypes) { dto.VoluntaryPlanWaiverRequestTypes.Add(voluntaryPlanWaiverRequestType.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } return(dto); }
/// <summary>Convert from VoluntaryPlanWaiverRequest DTO to entity</summary> /// <param name="dbContext">DB Context to use for attaching entity</param> /// <param name="dto">DTO to convert from</param> /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param> /// <returns>Resultant VoluntaryPlanWaiverRequest entity</returns> public static VoluntaryPlanWaiverRequest FromDto(FACTS.Framework.DAL.DbContext dbContext, VoluntaryPlanWaiverRequestDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null) { dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>(); if (dtoEntities.ContainsKey(dto)) { return((VoluntaryPlanWaiverRequest)dtoEntities[dto]); } VoluntaryPlanWaiverRequest entity = new VoluntaryPlanWaiverRequest(); dtoEntities.Add(dto, entity); Form.FromDtoSet(dbContext, dto, entity, dtoEntities); FromDtoSet(dbContext, dto, entity, dtoEntities); if (dbContext != null) { dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified)); } return(entity); }