Пример #1
0
        public IActionResult Update([FromBody] StairsViewModel viewModel)
        {
            if (!this.ModelState.IsValid ||
                !viewModel.Id.HasValue)
            {
                return(this.BadRequest("Model is not valid"));
            }

            try
            {
                var domainModel = new Stairs(
                    viewModel.Coordinates,
                    viewModel.Width,
                    viewModel.Length,
                    viewModel.Id.Value,
                    viewModel.StartFloor,
                    viewModel.EndFloor);

                this.updateStairsCommand.StairsToUpdate = domainModel;
                this.updateStairsCommand.Execute();
                return(this.Ok());
            }
            catch (RoomIsIntersectedWithExisting)
            {
                return(this.BadRequest("Stairs conflicts with other objects"));
            }
            catch (InvalidStairsFloorsException)
            {
                return(this.BadRequest("Stairs floors are invalid"));
            }
        }
Пример #2
0
 public IActionResult Create([FromBody] StairsViewModel viewModel)
 {
     if (!this.ModelState.IsValid)
     {
         return(this.BadRequest("Model is not valid"));
     }
     try
     {
         this.createStairs.StairsToCreate = Mapper.Map <Stairs>(viewModel);
         this.createStairs.Execute();
         return(this.Ok());
     }
     catch (RoomIsIntersectedWithExisting)
     {
         return(this.BadRequest("Stairs conflicts with other objects"));
     }
     catch (InvalidStairsFloorsException)
     {
         return(this.BadRequest("End floor con not be bigger then start floor"));
     }
 }