Пример #1
0
        public async Task <ServiceResponse <bool> > EditFlat(FlatFullInformationViewModel flatViewModel)
        {
            if (flatViewModel == null)
            {
                return(ServiceResponse <bool> .Warning("Did not receive flat's information"));
            }

            if (flatViewModel.Id == default(int))
            {
                return(ServiceResponse <bool> .Warning("Couldn't find a flat with an empty identifier"));
            }

            if (flatViewModel.KitchenArea >= flatViewModel.FullArea)
            {
                return(ServiceResponse <bool> .Warning("Kitchen area should be less than full area"));
            }

            var flat = await _flatRepository.GetById(flatViewModel.Id);

            if (flat == null)
            {
                return(ServiceResponse <bool> .Warning($"Couldn't find a flat with id = {flatViewModel.Id}"));
            }

            flat.FullArea    = flatViewModel.FullArea;
            flat.KitchenArea = flatViewModel.KitchenArea;
            flat.Floor       = flatViewModel.Floor;
            flat.Cost        = flatViewModel.Cost;

            return(ServiceResponse <bool> .Ok(await _flatRepository.Save(flat)));
        }
Пример #2
0
 public async Task <ServiceResponse <bool> > EditFlat([FromBody] FlatFullInformationViewModel model)
 {
     try
     {
         return(await _flatService.EditFlat(model));
     }
     catch (Exception e)
     {
         _logger.LogError(e, $"exception in EditFlat, called with {model}");
         return(ServiceResponse <bool> .Exception("An error occured during edit-flat request"));
     }
 }