public Response <string> UpdateCustomerOrdersField(int Id, [FromBody] JsonPatch.Model.PatchOperation fieldvalue)
        {
            var existingcustomer = CustomerMockData.CustomerList.Where(x => x.Id == Id).FirstOrDefault();
            var op = new JsonPatch.JsonPatchDocument <CustomerDetails>();

            op.Add(fieldvalue.path, fieldvalue.value);
            op.ApplyUpdatesTo(existingcustomer);
            return(new Response <string>()
            {
                Body = "Updated successfully.", Code = Status.Success
            });
        }
        public Response <string> UpdateAllCustomerField([FromBody] JsonPatch.Model.PatchOperation fieldvalue)
        {
            var existingcustomer = CustomerMockData.CustomerList;
            var op = new JsonPatch.JsonPatchDocument <CustomerDetails>();

            foreach (CustomerDetails c in existingcustomer)
            {
                op.Add(fieldvalue.path, fieldvalue.value);
                op.ApplyUpdatesTo(c);
            }
            return(new Response <string>()
            {
                Body = "Updated successfully.", Code = Status.Success
            });
        }
        public Response <string> UpdateCustomerOrders(int Id, [FromBody] JsonPatch.Model.PatchOperation fieldvalue)
        {
            var CustDetails = OrderMockData.CustomerOrders.Where(x => x.CustomerId == Id).FirstOrDefault();
            var CustOrders  = CustDetails.OrderList;
            var op          = new JsonPatch.JsonPatchDocument <Order>();

            foreach (var order in CustOrders)
            {
                op.Add(fieldvalue.path, fieldvalue.value);
                op.ApplyUpdatesTo(order);
            }
            return(new Response <string>()
            {
                Body = "Updated.", Code = Status.Success
            });
        }
        public IHttpActionResult Update([FromBody]
                                        JsonPatch.JsonPatchDocument <PersonnelDismissalEntrancePatchDto> patchDoc, int id)
        {
            if (patchDoc == null || !patchDoc.HasOperations)
            {
                return(BadRequest(AppSettings.PATCH_REQUEST_ERROR_MESSAGE));
            }
            if (patchDoc.Operations
                .Exists(q => q.Operation != JsonPatch.JsonPatchOperationType.replace))
            {
                return(BadRequest(AppSettings.PATCH_OPERATION_ERROR_MESSAGE));
            }
            if (!ModelState.IsValid)
            {
                string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
                return(BadRequest(errorMessage));
            }
            var _partialUpdateDto = _personnelDismissalEntranceService.PrepareForPartialUpdate(id);

            if (_partialUpdateDto == null)
            {
                return(BadRequest(AppSettings.NOT_FOUND_ERROR_MESSAGE));
            }
            try
            {
                patchDoc.ApplyUpdatesTo(_partialUpdateDto.PatchDto);
                _personnelDismissalEntranceService.ApplyPartialUpdate(_partialUpdateDto);
            }
            catch (LogicalException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (JsonPatch.JsonPatchException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
            }
            return(Ok());
        }
Exemplo n.º 5
0
        public NOPVData UpdateDetails(string bbl, JsonPatch.JsonPatchDocument <NOPVData> data)
        {
            NOPVData entity = dbContext.NOPVDatas.FirstOrDefault(b => b.BBL == bbl);

            if (entity == null)
            {
                throw new Exception("BBL not found");
            }

            try
            {
                //dbContext.Entry(entity).CurrentValues.SetValues(data);
                data.ApplyUpdatesTo(entity);
                //dbContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                dbContext.SaveChanges();
                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while updating data", ex);
            }
        }