示例#1
0
        public ActionResult AddItemToOrder(AddItemToOrderModel obj)
        {
            MessageModel model = new MessageModel();

            OrderBusinessLogic objOrderBusinessLogic = new OrderBusinessLogic();

            try
            {
                objOrderBusinessLogic.AddItemToOrder(obj);
                model.Message = "Item added in Order successfully";
            }
            catch (System.Exception ex)
            {
                model.Message = "An error has occured while adding Item to Order";
                model.Type    = Enumeration.MessageType.Error;
                logger.Error(model.Message, ex);
            }

            var response = new
            {
                //Status = updatedStatus,
                MessageModel = model
            };

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public void AddItemToOrder(AddItemToOrderModel model)
        {
            var item = db.Items.Find(model.ItemId);

            if (model.OrderId == 0)
            {
                Order o = new Order();
                o.IsDispatched  = false;
                o.ModifiedDate  = DateTime.Now.Date;
                o.CreatedBy     = (int)GetLoggedInUserId();
                o.CreatedDate   = DateTime.Now.Date;
                o.DistributorId = (int)item.DistributorId;
                db.Orders.Add(o);
                db.SaveChanges();

                OrderDetail od = new OrderDetail();
                od.OrderId      = o.OrderId;
                od.ItemId       = item.ItemId;
                od.Quantity     = model.Quantity;
                od.AddedOn      = DateTime.Now.Date;
                od.IsDispatched = false;

                db.OrderDetails.Add(od);
                db.SaveChanges();
            }
            else
            {
                var order = db.Orders.Find(model.OrderId);
                order.ModifiedDate    = DateTime.Now.Date;
                db.Entry(order).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                if (model.OrderDetailId == 0)
                {
                    OrderDetail od = new OrderDetail();
                    od.OrderId      = order.OrderId;
                    od.ItemId       = item.ItemId;
                    od.Quantity     = model.Quantity;
                    od.AddedOn      = DateTime.Now.Date;
                    od.IsDispatched = false;

                    db.OrderDetails.Add(od);
                    db.SaveChanges();
                }
                else
                {
                    var od = db.OrderDetails.Find(model.OrderDetailId);
                    od.Quantity = model.Quantity;
                    od.AddedOn  = DateTime.Now.Date;

                    db.Entry(od).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
示例#3
0
        public AddItemToOrderModel GetItemFromOrder(int itemId)
        {
            AddItemToOrderModel obj = new AddItemToOrderModel();
            var item = db.Items.Find(itemId);

            obj.ItemId   = item.ItemId;
            obj.Item     = item.Name;
            obj.Category = item.Category.Name;
            if (db.Orders.Any(c => c.DistributorId == item.DistributorId && c.IsDispatched == false))
            {
                var order = db.Orders.FirstOrDefault(c => c.DistributorId == item.DistributorId && c.IsDispatched == false);

                if (order.OrderDetails.Any(c => c.ItemId == item.ItemId && c.IsDispatched == false))
                {
                    var odrdet = order.OrderDetails.FirstOrDefault(c => c.ItemId == item.ItemId && c.IsDispatched == false);
                    obj.OrderId       = odrdet.OrderId;
                    obj.OrderDetailId = odrdet.OrderDetailId;
                    obj.Quantity      = odrdet.Quantity;
                    // obj.ItemId = odrdet.ItemId;
                    obj.DistributorId = (int)item.DistributorId;
                }
                else
                {
                    obj.OrderId       = order.OrderId;
                    obj.OrderDetailId = 0;
                    obj.Quantity      = 1;
                    //   obj.ItemId = itemId;
                    obj.DistributorId = (int)item.DistributorId;
                }
            }
            else
            {
                obj.OrderId       = 0;
                obj.OrderDetailId = 0;
                obj.Quantity      = 1;
                //obj.ItemId = itemId;
                obj.DistributorId = (int)item.DistributorId;
            }

            return(obj);
        }