コード例 #1
0
        public ActionResult OrderSend(IndexSelectNotificationsMV test, string pickedPerProvider, int? NotificationId)
        {
            // load the Final Approval
            //  int position = 1;
            //  GetSelectIndex().lineCollection.IngredientsList.Where(x => x.ProvidersList.Select(y => y.OrderInList).FirstOrDefault() == position);

            //   var list = GetSelectIndexstring s = pickedPerProvider;
            int position = pickedPerProvider.LastIndexOf(',');
            var idProvider = pickedPerProvider.Substring(position + 1);

            var stringIngredient = pickedPerProvider.Substring(0, position);

            var idIngredient = from val in stringIngredient.Split(',')
                               select int.Parse(val);

            var orderList = from orderL in db.ProviderPostIngredients
                            where orderL.ProviderId == idProvider
                            && idIngredient.Contains(orderL.ProviderPostIngredientId)
                                    select orderL;

            //   var oo = orderList.ToList();

               //Create new standard
               var order = new Order();
               order.CreatedDate = DateTime.Now;
               order.Status="New";
            order.RestaurantId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            foreach (var ii in orderList){

                  var oi = new OrderIngredient();
                oi.TotalRequired = ii.TotalRequired;
                oi.UnitCost = ii.UnitCost;
                oi.TotalCost = ii.TotalCost;
                oi.NotificationId = NotificationId.GetValueOrDefault();
                oi.IngredientId = ii.IngredientId;

                order.OrderIngredients.Add(oi);
            }

               db.Orders.Add(order);
               //Save whole entity graph to the database
               try
               {
               db.SaveChanges();
               _notification = "Order Sent";
               }
               catch (Exception e) {

               ModelState.AddModelError("","Error DB");

               }
            /// Lo de arriba esta funcionando

             int  id = NotificationId.GetValueOrDefault();

               //if (id == null)
               //{
               //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
               //}

             Notification notification = db.Notifications.Find(id);
               //if (notification == null)
               //{
               //    return HttpNotFound();
               //}

               var objPost = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).GroupBy(x => x.Ingredient.Name).ToList();
               var objProviderC = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).GroupBy(x => x.ProviderId).Count();
               IndexSelectNotificationsMV objPost2 = new IndexSelectNotificationsMV(); ///Origin do not delete

               objPost2.ProviderCount = objProviderC;

               foreach (var a in objPost)
               {
                   IngredientesMv objIng = new IngredientesMv();

                   int count = 0;
                   foreach (var b in a.OrderByDescending(x => x.ProviderId))
                   {
                       ProvidersMv objProvider = new ProvidersMv();
                       objProvider.ProviderName = db.Users.Where(x => x.Id == b.ProviderId).Select(x => x.UserName).FirstOrDefault();
                       objProvider.ProviderPostIngredientId = b.ProviderPostIngredientId;
                       objProvider.OrderInList = count++;
                       objProvider.IngredientName = b.Ingredient.Name;
                       objProvider.ProviderId = b.ProviderId;
                       objProvider.Picked = (stringIngredient.Contains(b.ProviderPostIngredientId.ToString())) ? true : false;
                       objIng.ProvidersList.Add(objProvider);

                   }

                   objIng.IngredientName = a.Select(x => x.Ingredient.Name).FirstOrDefault();
                   objPost2.provTop = objIng.ProvidersList;
                   objPost2.IngredientsList.Add(objIng);

               }

               GetSelectIndex().lineCollection = objPost2;
               ViewBag.NotificationId = NotificationId;

            return RedirectToAction("NotificationDetails", GetSelectIndex().lineCollection);
        }
コード例 #2
0
        public ActionResult NotificationDetails(int? id)
        {
            id = (id != null) ? id : GetSendOrdersession().notificationId; // GGMS Remove

            if (GetSelectIndex().lineCollection.IngredientsList.Count() == 0)
            {

                //if (id == null)
                //{
                //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                //}

                Notification notification = db.Notifications.Find(id);
                //if (notification == null)
                //{
                //    return HttpNotFound();
                //}

                var objPost = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).GroupBy(x => x.Ingredient.Name).ToList();
                var objProviderC = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).GroupBy(x => x.ProviderId).Count();
                var objProviderD = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).Select(x=> x.ProviderId).ToList();
                IndexSelectNotificationsMV objPost2 = new IndexSelectNotificationsMV(); ///Origin do not delete

                var distictObj = objProviderD.Distinct();

                objPost2.ProviderCount = objProviderC;

                foreach (var a in objPost)
                {
                    IngredientesMv objIng = new IngredientesMv();

                    int count = 0;
                    // foreach (var b in a.OrderByDescending(x => x.ProviderId))

                    foreach (var b in a)
                    {
                        ProvidersMv objProvider = new ProvidersMv();
                        objProvider.ProviderName = db.Users.Where(x => x.Id == b.ProviderId).Select(x => x.UserName).FirstOrDefault();
                        objProvider.ProviderPostIngredientId = b.ProviderPostIngredientId;
                        objProvider.OrderInList = count++;
                        objProvider.IngredientName = b.Ingredient.Name;
                        objProvider.ProviderId = b.ProviderId;
                       // objProvider.Picked = (count == 1) ? true : false;
                        objProvider.UnitCost = b.UnitCost;
                        objProvider.TotalCost = b.TotalCost;
                        objProvider.DateExpired = b.DateExpired;

                        objIng.ProvidersList.Add(objProvider);

                        if (objPost2.provTop.Where(x => x.ProviderId == objProvider.ProviderId).Count() <= 0)
                        {
                            objPost2.provTop.Add(objProvider);
                        }
                    }

                    foreach (var s in distictObj)
                    {
                        if (objIng.ProvidersList.Where(x => x.ProviderId == s).Count() <= 0)
                        {
                            ProvidersMv objProvider = new ProvidersMv();
                            objProvider.ProviderId = s;

                            objIng.ProvidersList.Add(objProvider);
                        }

                    }

                    //foreach(var d in objProviderD.Where(s=)))
                    //{
                    //    ProvidersMv objProvider = new ProvidersMv();

                    //}

                    objIng.ProvidersList = objIng.ProvidersList.OrderByDescending(x=> x.ProviderId).ToList();

                    objIng.IngredientName = a.Select(x => x.Ingredient.Name).FirstOrDefault();
                    objIng.TotalRequired = a.Select(x => x.TotalRequired).FirstOrDefault();
                    objIng.UnidName = a.Select(x => x.Unit.Name).FirstOrDefault();

                    objPost2.IngredientsList.Add(objIng);
                }

                GetSelectIndex().lineCollection = objPost2;
            }

            ViewBag.pickedPerProvider = "";

            ViewBag.Alertify = TempData["justSent"];
            ViewBag.NotificationId = id;
            return View(GetSelectIndex().lineCollection);
        }