protected async override Task <Either <CommandResult, Error> > ExecuteCommand(SpaceUpdateCommand command) { if (!(await service.DoesSpaceExist(command.Space))) { return(new NotFoundError()); } await service.Update(command.Space, command.Update, command.User); return(Success()); }
public async Task <IActionResult> Update(string id, SpaceViewModel spaceIn) { if (ModelState.IsValid) { var space = await _spaceService.Get(id); if (space == null) { return(NotFound()); } try { if (spaceIn.assets.Any()) { var assets = await _assetService.Get(spaceIn.assets); space.assests = assets; } else { space.assests = new List <Asset>(); } space.Capacity = spaceIn.Capacity; space.Name = spaceIn.Name; space.SpaceTypeId = spaceIn.SpaceTypeId; space.Tags = spaceIn.Tags; await _spaceService.Update(space); } catch (RessourceTypeRepositoryException ex) { ModelState.AddModelError(ex.Field, ex.Message); return(BadRequest(new ValidationProblemDetails(ModelState))); } catch (SpaceRepositoryException ex) { ModelState.AddModelError(ex.Field, ex.Message); return(BadRequest(new ValidationProblemDetails(ModelState))); } catch (AssetRepositoryException ex) { ModelState.AddModelError(ex.Field, ex.Message); return(BadRequest(new ValidationProblemDetails(ModelState))); } return(CreatedAtRoute("GetSpace", new { id = space.Id.ToString() }, space)); } return(BadRequest(new ValidationProblemDetails(ModelState))); }
public IActionResult Update(int id, [FromBody] UpdateSpaceModel model) { var context = HttpContext.User.Identity; var userId = int.Parse(context.Name); var space = _mapper.Map <Space>(model); space.Id = id; try { _spaceService.Update(userId, space); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }