public IHttpActionResult PutLocation(LocationEditVM location)
        {
            AuthenticationHeaderValue authenticationHeaderValue = Request.Headers.Authorization;
            var    userNamePasswordString = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationHeaderValue.Parameter));
            string usrename = userNamePasswordString.Split(':')[0];
            string password = userNamePasswordString.Split(':')[1];

            int userId = GetUserId(usrename);

            var loc = db.Location.Where(x => x.Id == location.Id && x.UserId == userId).FirstOrDefault();

            if (loc == null)
            {
                return(Ok());
            }


            loc.Name        = location.Name;
            loc.Long        = location.Long;
            loc.Lat         = location.Lat;
            loc.UpdatedDate = DateTime.Now;


            db.Entry(loc).State = EntityState.Modified;

            db.SaveChanges();


            return(CreatedAtRoute("DefaultApi", new { controller = "locations", id = loc.Id }, loc));
        }
 public ActionResult Details(LocationEditVM inventory2BUpdated)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (cart.OrderItems == null || cart.LocationID != inventory2BUpdated.LocationId)
             {
                 cart.OrderItems = new List <OrderItems>();
                 cart.OrderItems.Clear();
             }
             _logger.LogWarning($"User has added {inventory2BUpdated.ProductName} to their cart!");
             Inventory chosenInventory = _mapper.cast2Inventory(inventory2BUpdated);
             chosenInventory.InventoryProduct = _storeBL.GetInventory(inventory2BUpdated.InventoryId).InventoryProduct;
             OrderItems currentItem = new OrderItems {
                 OrderQuantity    = chosenInventory.InventoryQuantity,
                 OrderItemProduct = chosenInventory.InventoryProduct,
                 ProductID        = chosenInventory.InventoryProduct.Id
             };
             cart.LocationID = inventory2BUpdated.LocationId;
             cart.OrderItems.Add(currentItem);
             return(RedirectToAction("Details", "Location", new { Id = (int)HttpContext.Session.GetInt32("LocationID") }));
         }
         catch
         {
             return(View());
         }
     }
     return(View());
 }
 public ActionResult Edit(LocationEditVM inventory2BUpdated)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _storeBL.UpdateInventory(_mapper.cast2Inventory(inventory2BUpdated));
             _logger.LogWarning($"Inventory with Id: {inventory2BUpdated.InventoryId} has been updated");
             return(RedirectToAction(nameof(Index)));
         }
         catch
         {
             return(View());
         }
     }
     return(View());
 }