public static TaxSchedule MapToEntity(this TaxScheduleCreateDto dto) { var entity = new TaxSchedule(); switch (dto.ScheduleType) { case ScheduleType.Daily: entity.TaxEndDate = dto.TaxStartDate.Date; break; case ScheduleType.Weekly: entity.TaxEndDate = dto.TaxStartDate.AddDays(6).Date; break; case ScheduleType.Monthly: entity.TaxEndDate = dto.TaxStartDate.AddMonths(1).AddDays(-1).Date; break; case ScheduleType.Yearly: entity.TaxEndDate = dto.TaxStartDate.AddYears(1).AddDays(-1).Date; break; default: break; } entity.ScheduleType = dto.ScheduleType; entity.TaxStartDate = dto.TaxStartDate.Date; entity.Tax = dto.Tax; entity.MunicipalityId = dto.MunicipalityId; return(entity); }
public IActionResult UpdateScheduleForMunicipality(Guid municipalityId, Guid taxScheduleId, [FromBody] TaxScheduleCreateDto body) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var municipalityExist = this.service.IsMunicipalityExist(municipalityId); if (!municipalityExist) { return(this.BadRequest($"Municipality doesn't exists or has no schedules")); } if (body.MunicipalityId != municipalityId) { return(this.BadRequest("Municipality Id in the route and the body have match eatch other")); } int retVal = this.service.UpdateSchedule(taxScheduleId, body); if (retVal == 0) { return(this.BadRequest($"No entities found to update")); } else { return(this.NoContent()); } }