public ActionResult PlaceOrder(SaveOrder model)
        {
            try
            {
                if (model != null)
                {
                    var UserId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
                    model.OrderBy = int.Parse(UserId);
                    var product           = _dbContext.Products.SingleOrDefault(x => x.ProductId == model.ProductId);
                    var availableQuantity = product.Quantity;
                    var appliedQuantity   = model.Quantity;

                    if (appliedQuantity > availableQuantity)
                    {
                        var resultReturnModel = new ReturnModelValue(enumReturnStatus.Failed, "There is no such quanties vailable", "Select Within a given quantity", null);
                        return(Ok(resultReturnModel));
                    }

                    else if (appliedQuantity == availableQuantity)
                    {
                        _dbContext.SaveOrders.Add(model);
                        _dbContext.SaveChanges();
                        var data = _dbContext.Products.SingleOrDefault(x => x.ProductId == model.ProductId);
                        _dbContext.Remove(data);
                        _dbContext.SaveChanges();
                        var resultReturnModel = new ReturnModelValue(enumReturnStatus.Success, "Order Purchase", "Purchased", null);
                        return(Ok(resultReturnModel));
                    }
                    else if (appliedQuantity < availableQuantity)
                    {
                        _dbContext.SaveOrders.Add(model);
                        _dbContext.SaveChanges();
                        var data            = _dbContext.Products.SingleOrDefault(x => x.ProductId == model.ProductId);
                        var CurrentQuantity = availableQuantity - appliedQuantity;
                        data.Quantity = CurrentQuantity;
                        _dbContext.Update(data);
                        _dbContext.SaveChanges();
                        var resultReturnModel = new ReturnModelValue(enumReturnStatus.Success, "Order Purchaes", "Purchased", null);
                        return(Ok(resultReturnModel));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
            return(null);
        }
 public async Task <IActionResult> DeleteProduct(int id)
 {
     try
     {
         var result = _dbContext.Products.SingleOrDefault(x => x.ProductId == id);
         if (result == null)
         {
             return(Ok(new ReturnModelValue(enumReturnStatus.Failed, "No product Found to be deleted", "No Product found.")));
         }
         else
         {
             _dbContext.Remove(result);
             _dbContext.SaveChanges();
             return(Ok(new ReturnModelValue(enumReturnStatus.Success, "Product Deleted", "Product deleted successfully.")));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }