public string UpdateDeliveryAddress(UpdateDeliveryAddressModel model)
        {
            try
            {
                using (dbContext)
                {
                    var delivery = dbContext.Deliveries.Find(model.Id);

                    if (delivery != null)
                    {
                        delivery.City              = model.City;
                        delivery.Complex           = model.Complex;
                        delivery.Fullnames         = model.Fullnames;
                        delivery.isResidential     = model.isResidential;
                        delivery.PostalCode        = model.PostalCode;
                        delivery.Province          = model.Province;
                        delivery.RecipientMobileNo = model.RecipientMobileNo;
                        delivery.StreetAddress     = model.StreetAddress;
                        delivery.Suburb            = model.Suburb;

                        dbContext.SaveChanges();
                    }
                    return("Seccusfully Removed !");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message.ToString());
            }
        }
Exemple #2
0
        public async Task <IActionResult> UpdateDeliveryAddress(int id)
        {
            UpdateDeliveryAddressModel deliveryAddress = new UpdateDeliveryAddressModel();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://localhost:44374/api/Delivery/GetCustomerDelivery/" + id))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    deliveryAddress = JsonConvert.DeserializeObject <UpdateDeliveryAddressModel>(apiResponse);
                }
            }
            return(View(deliveryAddress));
        }
 public ActionResult <UpdateDeliveryAddressModel> PutDelivery(int id, UpdateDeliveryAddressModel model)
 {
     try
     {
         if ((model == null) || (model.Id == 0))
         {
             return(NotFound());
         }
         _context.UpdateDeliveryAddress(model);
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!DeliveryExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(model);
 }
Exemple #4
0
        public async Task <IActionResult> UpdateDeliveryAddress(UpdateDeliveryAddressModel model)
        {
            using (var httpClient = new HttpClient())
            {
                string serailizedProduct = JsonConvert.SerializeObject(model);

                var inputMessage = new HttpRequestMessage
                {
                    Content = new StringContent(serailizedProduct, Encoding.UTF8, "application/json")
                };

                inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage message = httpClient.PutAsync("https://localhost:44374/api/Delivery/PutDelivery", inputMessage.Content).Result;

                if (!message.IsSuccessStatusCode)
                {
                    throw new ArgumentException(message.ToString());
                }

                return(RedirectToAction("Index"));
            }
        }