public async Task <IActionResult> Update(Guid societyId, Guid buildingId, Guid id, [FromBody] FlatUpdate flat) { if (flat == null) { return(BadRequest()); } var flatExists = await this._flatService.IsFlatInSocietyBuildingExistsAsync(societyId, buildingId, id); if (!flatExists) { return(NotFound()); } flat.UpdatedBy = this.LoggedInUserId; flat.UpdatedDate = DateTime.UtcNow; var response = await this._flatService.UpdateFlatAsync(societyId, buildingId, id, flat); if (response.Successful) { return(NoContent()); } return(BadRequest(response.ErrorMessages)); }
public async Task <ServiceResponse <Flat> > UpdateFlatAsync(Guid societyId, Guid buildingId, Guid flatId, FlatUpdate flat) { var validator = new FlatUpdateValidator(); var results = validator.Validate(flat); var response = new ServiceResponse <Flat>(); response.ErrorMessages = results.Errors.ToList(); if (!response.Successful) { return(response); } var updatedEntity = AutoMapper.Mapper.Map <Apollo.Domain.Entity.Society.Flat>(flat); updatedEntity.Id = flatId; updatedEntity.SocietyId = societyId; updatedEntity.BuildingId = buildingId; var result = await this._flatRepository.UpdateAsync(updatedEntity); response.Data = AutoMapper.Mapper.Map <Apollo.Domain.DTO.Society.Flat>(result); return(response); }