public IHttpActionResult PutOrder_Items(string id, Order_Items order_Items)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order_Items.Order_ID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Order_ItemsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostOrder_Items(Order_Items order_Items)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Order_Items.Add(order_Items);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (Order_ItemsExists(order_Items.Order_ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = order_Items.Order_ID }, order_Items));
        }
Ejemplo n.º 3
0
        public static void SetOrderItem(this Order_Items orderItem, CartItemViewModel model)
        {
            try
            {
                using (SkriblContext ctx = new SkriblContext())
                {
                    switch (model.ItemType)
                    {
                    case (int)CartItemTypes.Product:
                        orderItem.Product_Id = model.ItemId;
                        var product = ctx.Products.FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                        orderItem.Name        = product.Name;
                        orderItem.Price       = product.Price * model.Qty;
                        orderItem.Description = product.Description;
                        product.OrderedCount  = product.OrderedCount + model.Qty;
                        ctx.SaveChanges();
                        break;

                    case (int)CartItemTypes.Package:
                        orderItem.Package_Id = model.ItemId;
                        var package = ctx.Packages.FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                        orderItem.Name        = package.Name;
                        orderItem.Price       = package.Price * model.Qty;
                        orderItem.Description = package.Description;
                        break;

                    case (int)CartItemTypes.Offer_Product:
                        orderItem.Offer_Product_Id = model.ItemId;
                        var offerProduct = ctx.Offer_Products.Include(x => x.Product).FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                        orderItem.Name        = offerProduct.Product.Name;
                        orderItem.Price       = offerProduct.DiscountedPrice * model.Qty;
                        orderItem.Description = offerProduct.Description;
                        break;

                    case (int)CartItemTypes.Offer_Package:
                        orderItem.Offer_Package_Id = model.ItemId;
                        var offerPackage = ctx.Offer_Packages.Include(x => x.Package).FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                        orderItem.Name        = offerPackage.Package.Name;
                        orderItem.Price       = offerPackage.DiscountedPrice * model.Qty;
                        orderItem.Description = offerPackage.Description;
                        break;

                    default:
                        throw new Exception("Invalid CartItemType");
                    }
                }

                orderItem.Qty = model.Qty;
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Order_Items order_Items = db.Order_Items.Find(id);

            db.Order_Items.Remove(order_Items);
            Product prod = db.Product.Find(order_Items.ProductId);

            prod.QuantityInStock = prod.QuantityInStock + order_Items.Order_Quantity;
            db.Entry(prod).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Details", "Orders", new { id = order_Items.OrderId }));
        }
Ejemplo n.º 5
0
 public static void AddNewOrderItem(this StoreOrder storeOrder, CartItemViewModel model, DunkeyContext ctx)
 {
     try
     {
         Order_Items orderItem = new Order_Items();
         orderItem.SetOrderItem(model, ctx);
         storeOrder.Order_Items.Add(orderItem);
     }
     catch (Exception ex)
     {
         DunkeyDelivery.Utility.LogError(ex);
     }
 }
Ejemplo n.º 6
0
 public static void AddNewOrderItem(this StoreOrder storeOrder, CartItemViewModel model)
 {
     try
     {
         Order_Items orderItem = new Order_Items();
         orderItem.SetOrderItem(model);
         storeOrder.Order_Items.Add(orderItem);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 7
0
        public static void SetOrderItem(this Order_Items orderItem, CartItemViewModel model, DunkeyContext ctx)
        {
            try
            {
                switch (model.ItemType)
                {
                case (int)CartItemTypes.Product:
                    orderItem.Product_Id = model.ItemId;
                    var product = ctx.Products.FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                    orderItem.Name        = product.Name;
                    orderItem.Price       = Convert.ToDouble(product.Price);
                    orderItem.Description = product.Description;
                    break;

                case (int)CartItemTypes.Package:
                    orderItem.Package_Id = model.ItemId;
                    var package = ctx.Packages.FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                    orderItem.Name        = package.Name;
                    orderItem.Price       = Convert.ToDouble(package.Price);
                    orderItem.Description = package.Description;
                    break;

                case (int)CartItemTypes.Offer_Product:
                    orderItem.Offer_Product_Id = model.ItemId;
                    var offerProduct = ctx.Offer_Products.Include(x => x.Product).FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                    orderItem.Name        = offerProduct.Product.Name;
                    orderItem.Price       = offerProduct.DiscountedPrice * model.Qty;
                    orderItem.Description = offerProduct.Description;
                    break;

                case (int)CartItemTypes.Offer_Package:
                    orderItem.Offer_Package_Id = model.ItemId;
                    var offerPackage = ctx.Offer_Packages.Include(x => x.Package).FirstOrDefault(x => x.Id == model.ItemId && x.IsDeleted == false);
                    orderItem.Name        = offerPackage.Package.Name;
                    orderItem.Price       = offerPackage.DiscountedPrice * model.Qty;
                    orderItem.Description = offerPackage.Description;
                    break;

                default:
                    throw new Exception("Invalid CartItemType");
                }


                orderItem.Qty = model.Qty;
            }
            catch (Exception ex)
            {
                DunkeyDelivery.Utility.LogError(ex);
            }
        }
        public IHttpActionResult DeleteOrder_Items(string id)
        {
            Order_Items order_Items = db.Order_Items.Find(id);

            if (order_Items == null)
            {
                return(NotFound());
            }

            db.Order_Items.Remove(order_Items);
            db.SaveChanges();

            return(Ok(order_Items));
        }
Ejemplo n.º 9
0
        // GET: Order_Items/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Order_Items order_Items = db.Order_Items.Where(i => i.Id == id).Include(o => o.Order).Include(p => p.Product).Include(or => or.Order.Customer).First();

            if (order_Items == null)
            {
                return(HttpNotFound());
            }
            return(View(order_Items));
        }
Ejemplo n.º 10
0
        public async Task <bool> SaveOrder(OrderDto dto)
        {
            dto.order_Value = dto.DetailsItem.Sum(i => i.Item_Agreed_Price * i.Item_Number);
            Order orderdata = BOMapper.Map <OrderDto, Order>(dto);

            OrdersRepo.Add(orderdata);
            dto.DetailsItem.ForEach(i => {
                Order_Items orderItemw = BOMapper.Map <OrderDetailsDto, Order_Items>(i);
                OrderItems.Add(orderItemw);
            });
            int retValue = await UnitOfWork.Complete();

            return(retValue > 0);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Save the order in database
        /// </summary>
        /// <param name="data"></param>
        /// <param name="ShippingCharge"></param>
        /// <param name="_tax"></param>
        /// <param name="GrandTotal"></param>
        /// <param name="description"></param>
        private void SavePayments(List <string> data, string ShippingCharge, string _tax, string GrandTotal, string description, string _cartemail, string _cartphone, string _phoneType, string _acceptMessage)
        {
            try
            {
                string SubTotal = data[1];
                var    Items    = JsonConvert.DeserializeObject <List <ItemModel> >(data[0]);

                db_AirborneEntities OEM = new db_AirborneEntities();
                Order_Payments      _objOrderPayment = new Order_Payments();
                _objOrderPayment.OrderID          = OrderId;
                _objOrderPayment.OrderDescription = description;
                _objOrderPayment.OrderPrice       = Convert.ToDecimal(GrandTotal);
                _objOrderPayment.OrderItems       = Items.Count;
                _objOrderPayment.Email            = _cartemail;
                _objOrderPayment.PhoneNumber      = _cartphone;
                _objOrderPayment.ShippingAddress  = "";
                _objOrderPayment.Status           = "0";
                _objOrderPayment.ShippingPrice    = Convert.ToDecimal(ShippingCharge);
                _objOrderPayment.Tax           = Convert.ToDecimal(_tax);
                _objOrderPayment.CreatedDate   = DateTime.UtcNow;
                _objOrderPayment.PhoneType     = (string.IsNullOrEmpty(_phoneType)) ? false : ((_phoneType.ToString().ToLower() == "true") ? true : false);
                _objOrderPayment.AcceptMessage = (string.IsNullOrEmpty(_acceptMessage)) ? false : ((_acceptMessage.ToString().ToLower() == "true") ? true : false);

                OEM.Order_Payments.Add(_objOrderPayment);

                foreach (var Product in Items)
                {
                    Order_Items _objOrderItem = new Order_Items();
                    _objOrderItem.OrderID         = _objOrderPayment.OrderID;
                    _objOrderItem.Price           = Convert.ToDecimal(Product.Item_Price);
                    _objOrderItem.ProductCode     = Product.Item_code.ToString();
                    _objOrderItem.ProductName     = Product.Item_Name;
                    _objOrderItem.Quantity        = Product.ItemCounts;
                    _objOrderItem.TotalPrice      = Product.ItemTotalPrice;
                    _objOrderItem.ProductID       = Convert.ToInt64(Product.Item_ID);
                    _objOrderItem.ShippingPerUnit = Product.ItemShippingCost;
                    _objOrderItem.TaxPerUnit      = Product.ItemTax;
                    _objOrderItem.CreatedDate     = DateTime.UtcNow;
                    OEM.Order_Items.Add(_objOrderItem);
                }
                OEM.SaveChanges();
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "Id, ProductId, Order_Quantity")] Order_Items order_Items, int?orderId)
        {
            Product prod = db.Product.Find(order_Items.ProductId);

            if (prod.QuantityInStock < order_Items.Order_Quantity)
            {
                ModelState.AddModelError("", "Our warehouse contains only " + prod.QuantityInStock);
                ViewBag.ProductId = new SelectList(db.Product, "Id", "Name");
                return(View(order_Items));
            }

            if (ModelState.IsValid)
            {
                order_Items.Order   = db.Orders.Find(orderId);
                order_Items.OrderId = orderId.Value;
                db.Order_Items.Add(order_Items);
                prod.QuantityInStock = prod.QuantityInStock - order_Items.Order_Quantity;
                db.Entry(prod).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details", "Orders", new { id = order_Items.OrderId }));
            }
            ViewBag.ProductId = new SelectList(db.Product, "Id", "Name");
            return(View(order_Items));
        }