public async Task <IHttpActionResult> AddHiveSectionAsync([FromBody] UpdateHiveSectionRequest createRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var hiveSection = await _hiveSectionService.CreateHiveSectionAsync(createRequest); var location = $"/api/sections/{hiveSection.Id}"; return(Created <HiveSection>(location, hiveSection)); } catch (RequestedResourceHasConflictException) { return(Conflict()); } catch (RequestedResourceNotFoundException) { return(NotFound()); } }
public async Task UpdateHiveSection_TryUpdateHiveSection_HiveSectionUpdated( [Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service) { var existedHiveSection = new StoreHiveSection { Id = 1, Code = "Code" }; var newHiveSection = new UpdateHiveSectionRequest { Code = "newCode" }; context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { existedHiveSection }); await service.UpdateHiveSectionAsync(existedHiveSection.Id, newHiveSection); var updatedHiveSection = context.Object.Sections.First(h => h.Id == existedHiveSection.Id); Assert.True(updatedHiveSection.Code == newHiveSection.Code); }
public async Task <IHttpActionResult> AddSectionAsync([FromUri] int?hiveId, [FromBody] UpdateHiveSectionRequest updateRequest) { if (hiveId == null || updateRequest == null) { return(BadRequest()); } try { var hiveSection = await _hiveSectionService.CreateHiveSectionAsync(hiveId.Value, updateRequest); var location = $"/api/sections/{hiveSection.Id}"; return(Created <HiveSection>(location, hiveSection)); } catch (RequestedResourceHasConflictException e) { return(Conflict()); } catch (Exception e) { return(InternalServerError()); } }
public async Task UpdateHiveSectionAsync_UpdateRequestAsParametr_ReturnedUpdatedElement() { var updateReq = new UpdateHiveSectionRequest() { Name = "UpdateName", Code = "TEST1", HiveId = 2 }; var hiveSectionId = 1; var storeContext = new Mock <IProductStoreHiveContext>(); var userContext = new Mock <IUserContext>(); storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives); storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections); var service = new HiveSectionService(storeContext.Object, userContext.Object); var hiveSection = await service.UpdateHiveSectionAsync(hiveSectionId, updateReq); Assert.Equal(updateReq.Name, hiveSection.Name); Assert.Equal(updateReq.Code, hiveSection.Code); Assert.Equal(updateReq.HiveId, hiveSection.HiveId); }
public async Task <IHttpActionResult> UpdateHiveSectionAsync([FromUri] int id, [FromBody] UpdateHiveSectionRequest updateRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _hiveSectionService.UpdateHiveSectionAsync(id, updateRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); }
public async Task <IHttpActionResult> UpdateHiveSection([FromUri] int hiveSectionId, [FromBody] UpdateHiveSectionRequest updateHiveRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _hiveSectionService.UpdateHiveSectionAsync(hiveSectionId, updateHiveRequest); return(Ok()); }
public async Task <IHttpActionResult> UpdateHiveSection([FromUri] int hiveSectionId, [FromBody] UpdateHiveSectionRequest hiveSectionRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var hive = await this._hiveSectionService.UpdateHiveSectionAsync(hiveSectionId, hiveSectionRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent, hive))); }
public async Task <IHttpActionResult> UpdateSectionAsync([FromUri] int?hiveSectionId, [FromBody] UpdateHiveSectionRequest updateRequest) { if (hiveSectionId == null || updateRequest == null || !ModelState.IsValid) { return(BadRequest()); } try { await _hiveSectionService.UpdateHiveSectionAsync(hiveSectionId.Value, updateRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); } catch (RequestedResourceHasConflictException e) { return(Conflict()); } catch (RequestedResourceNotFoundException e) { return(NotFound()); } catch (Exception e) { return(InternalServerError()); } }
public async Task <IHttpActionResult> UpdateHiveSection([FromUri] int hiveSectionId, [FromBody] UpdateHiveSectionRequest updateRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (updateRequest == null) { return(BadRequest($"The {nameof(updateRequest)} can`t be null.")); } await _hiveSectionService.UpdateHiveSectionAsync(hiveSectionId, updateRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); }
public async Task <IHttpActionResult> UpdateHiveSection([FromUri] int hiveSectionId, [FromBody] UpdateHiveSectionRequest updateRequest) { IHttpActionResult result = CheckRequest(updateRequest); if (result != null) { return(result); } await _hiveSectionService.UpdateHiveSectionAsync(hiveSectionId, updateRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); }
public async Task <IHttpActionResult> UpdateHiveSectionAsync([FromUri] int id, [FromBody] UpdateHiveSectionRequest updateRequest) { if (id < 1) { return(BadRequest($"Argument {nameof(id)} must be greater than zero.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _hiveSectionService.UpdateHiveSectionAsync(id, updateRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); } catch (RequestedResourceHasConflictException) { return(Conflict()); } catch (RequestedResourceNotFoundException) { return(NotFound()); } }
public async Task <IHttpActionResult> UpdateHiveSection([FromUri] int hiveSectionId, [FromBody] UpdateHiveSectionRequest updateRequest) { if (hiveSectionId < 1) { return(BadRequest($"{Resources.INVALI_ID_VALUE}{hiveSectionId}")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _hiveSectionService.UpdeteHiveSectionAsync(hiveSectionId, updateRequest); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); } catch (RequestedResourceHasConflictException) { return(Conflict()); } catch (RequestedResourceNotFoundException) { return(NotFound()); } catch (Exception e) { return(InternalServerError()); } }