public async Task <ActionResult> Put(Guid id, [FromBody] UpdateFieldViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UpdateFieldModel updateFieldModel = _mapper.Map <UpdateFieldModel>(model); updateFieldModel.Id = id; Field field = await _commands.Update(updateFieldModel); if (field is null) { return(NotFound()); } return(Ok(_mapper.Map <FieldDetailsViewModel>(field))); } catch (Exception ex) when(ex is ResourceStateException) { return(Conflict(new ErrorViewModel(ex))); } }
public async Task <IActionResult> UpdateField([FromBody] UpdateFieldModel model) { model.Hash = User.Claims.GetUserHash(); model.ID = User.Claims.GetUserId(); await _profileService.UpdateField(model); return(Ok("OK")); }
public async Task UpdateFieldReturnsNullIfFieldDoesNotExist() { // Given UpdateFieldModel model = ModelFactory.UpdateModel(Guid.NewGuid()); // When Field field = await _commands.Update(model); // Then field.Should().BeNull(); }
public ActionResult UpdateBasketDeliveryInstruction(string basketId, string deliveryInstruction) { if (!string.IsNullOrEmpty(basketId) && !string.IsNullOrEmpty(deliveryInstruction)) { var feildValue = new UpdateFieldModel { FieldValue = deliveryInstruction }; var resp = _checkoutApi.UpdateBasketDeliveryInstruction(Sanitizer.GetSafeHtmlFragment(basketId), feildValue); return(JsonSuccess(resp, JsonRequestBehavior.AllowGet)); } return(JsonSuccess("", JsonRequestBehavior.AllowGet)); }
public async Task UpdateFieldReturnsFieldOnSuccess() { // Given Field field = ModelFactory.DomainModel("Field B", 13, 37); Guid fieldId = SeedDatabase(field); UpdateFieldModel model = ModelFactory.UpdateModel(fieldId); // When field = await _commands.Update(model); // Then field.Should().NotBeNull(); field.Name.Should().Be("Field A"); field.Latitude.Should().Be(52); field.Longtitude.Should().Be(20); }
public void UpdateFieldThrowsExceptionOnNameConflict() { // Given Field existingField = ModelFactory.DomainModel(); SeedDatabase(existingField); Field updatedField = ModelFactory.DomainModel("Field B"); Guid updatedFieldId = SeedDatabase(updatedField); UpdateFieldModel model = ModelFactory.UpdateModel(updatedFieldId); // When Func <Task> updateField = async() => await _commands.Update(model); // Then updateField.Should().Throw <FieldWithNameAlreadyExistsException>(); }
public async Task <Field> Update(UpdateFieldModel model) { Field field = await _database.Fields.FindAsync(model.Id); if (field is null) { return(null); } IQueryable <Field> existingFieldsWithName = from existingField in _database.Fields where (existingField.Name == model.Name) && (existingField.Id != field.Id) select existingField; if (await existingFieldsWithName.AnyAsync()) { throw new FieldWithNameAlreadyExistsException(model.Name); } _mapper.Map(model, field); _database.Fields.Update(field); await _database.SaveAsync(); return(field); }
public async Task UpdateField(UpdateFieldModel model) { await _requestManagerService.Post <ServiceResponse <object> >("/profile_edit", model); }
public ResponseModel <BoolResponse> UpdateBasketDeliveryInstruction(string basketId, UpdateFieldModel deliveryInstruction) { return(CallApi <BoolResponse>(string.Format(ApiUrls.UpdateBasketDeliveryInstruction, basketId), JsonConvert.SerializeObject(deliveryInstruction), Method.POST)); }