Esempio n. 1
0
        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)));
            }
        }
Esempio n. 2
0
        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"));
        }
Esempio n. 3
0
        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));
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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>();
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 public async Task UpdateField(UpdateFieldModel model)
 {
     await _requestManagerService.Post <ServiceResponse <object> >("/profile_edit", model);
 }
Esempio n. 9
0
 public ResponseModel <BoolResponse> UpdateBasketDeliveryInstruction(string basketId, UpdateFieldModel deliveryInstruction)
 {
     return(CallApi <BoolResponse>(string.Format(ApiUrls.UpdateBasketDeliveryInstruction, basketId), JsonConvert.SerializeObject(deliveryInstruction), Method.POST));
 }