Esempio n. 1
0
        public async Task <UpdateFlatDto> UpdateFlatAsync(UpdateFlatDto updateFlatDto)
        {
            try
            {
                var flat = _dbContext.Flats
                           .Include(x => x.House)
                           .FirstOrDefault(x => x.Id == Guid.Parse(updateFlatDto.Flat.Id));

                if (_dbContext.Flats.FirstOrDefault(x => x.Id == Guid.Parse(updateFlatDto.Flat.Id)) is null)
                {
                    return new UpdateFlatDto
                           {
                               ItemNotFound = true,
                               Status       = false
                           }
                }
                ;

                //Can not make Flat duplicate because of EF Core
                flat = flat.UpdateFlatDtoToFlat(updateFlatDto);

                _dbContext.Flats.Update(flat);
                await _dbContext.SaveChangesAsync();

                var updatedFlatDto = flat.FlatToUpdateFlatDto();
                updatedFlatDto.Status = true;

                return(updatedFlatDto);
            }
            catch (Exception e)
            {
                _logger.LogError($"Error on updating Flat in database. Exception message: {e.Message};\nInner message: {e.InnerException?.Message}");
                return(new UpdateFlatDto
                {
                    Errors = new[] { "Error on updating Flat in database." },
                    ServerError = true,
                    Status = false
                });
            }
        }
Esempio n. 2
0
 public async Task <UpdateFlatDto> UpdateFlatAsync(UpdateFlatDto updateFlatDto) =>
 await _sqlFlatService.UpdateFlatAsync(updateFlatDto);
Esempio n. 3
0
        private static BBIT.Domain.Entities.Flat.Flat ConvertUpdateFlatRequestToUpdateFlatDto(ref BBIT.Domain.Entities.Flat.Flat flat, UpdateFlatDto updateFlatDto)
        {
            flat.Id            = Guid.Parse(updateFlatDto.Flat.Id);
            flat.FlatNumber    = updateFlatDto.Flat.FlatNumber;
            flat.Floor         = updateFlatDto.Flat.Level;
            flat.AmountOfRooms = updateFlatDto.Flat.AmountOfRooms;
            flat.TotalArea     = updateFlatDto.Flat.TotalArea;
            flat.HouseRoom     = updateFlatDto.Flat.HouseRoom;

            return(flat);
        }
Esempio n. 4
0
 public static BBIT.Domain.Entities.Flat.Flat UpdateFlatDtoToFlat(this BBIT.Domain.Entities.Flat.Flat flat, UpdateFlatDto updateFlatDto) =>
 ConvertUpdateFlatRequestToUpdateFlatDto(ref flat, updateFlatDto);