Esempio n. 1
0
        public ActionResult AddToOrder(OrderInfoDTO info)
        {
            if (!((bool?)this.Session["LoggedIn"] ?? false))
                return RedirectToAction("Login", "Account");

            if (Request.IsAjaxRequest())
            {
                try
                {
                    using (var proxy = factory.GetWorkChannel())
                    {
                        List<OrderIngredientDTO> ings = proxy.QueryIngredients(new QueryRequest<IngredientsQuery>
                        {
                            Query = new IngredientsQuery
                            {
                                Login = ((UserDTO)this.Session["User"]).Email,
                                Password = ((UserDTO)this.Session["User"]).Password,
                                IngredientIds = info.Ingredients
                            }
                        }).Data;

                        for (int i = 0; i < ings.Count; i++)
                        {
                            ings[i].Quantity = (info.Quantities[i] == "normal") ? ings[i].NormalWeight : ings[i].ExtraWeight;
                        }

                        double sizeValue = GetSize(info);

                        SizeDTO size = new SizeDTO { SizeValue = sizeValue };

                        List<OrderDetailDTO> od = new List<OrderDetailDTO>
                    {
                        new OrderDetailDTO
                        {
                            Ingredients=ings,
                            Size=size
                        }
                    };
                        OrderDTO data = new OrderDTO
                        {
                            OrderDetailsDTO = od
                        };

                        return PartialView("_OrderList", data);
                    }
                }
                catch (Exception e)
                {
                    return HandleFaults(e);
                }
            }
            return View();
        }
Esempio n. 2
0
        public static PriceData GetPrices(RecipeDTO r, SizeDTO[] sizes)
        {
            PriceData result = new PriceData() { PriceLow =  BASE_PRICE * sizes[0].SizeValue,
                PriceMed = BASE_PRICE * sizes[1].SizeValue, PriceHigh = BASE_PRICE * sizes[2].SizeValue };
            if (r.Ingredients == null)
                return result;

            foreach (var i in r.Ingredients)
            {
                if (sizes.Count() != 3) throw new Exception("Invalid sizes collection");
                result.PriceLow += i.NormalWeight * (double)i.Price * sizes[0].SizeValue;
                result.PriceMed += i.NormalWeight * (double)i.Price * sizes[1].SizeValue;
                result.PriceHigh += i.NormalWeight * (double)i.Price* sizes[2].SizeValue;
            }
            return result;
        }
 public IngredientsRow(OrderIngredientDTO ingredient, int currentQuantity, SizeDTO size)
     : this(ingredient, currentQuantity)
 {
     this.CurrentSize = size;
 }
 public IngredientsListItem(SizeDTO size)
 {
     this.Size = size;
 }
Esempio n. 5
0
        internal void ChangeCurrentSize(SizeDTO size)
        {
            // MODIFIED
            //RadioButton rb = sender as RadioButton;
            //if (rb == null) return;
            //var value = rb.Tag as PizzaNetDataModel.Model.Size;
            //if (value != null)
            //{
            //    CurrentSizeValue = value;
            //    foreach (var item in IngredientsCollection)
            //        item.CurrentSize = value;
            //}
            //RecalculatePrice();

            CurrentSizeValue = size;
            foreach (var item in IngredientsCollection)
                item.CurrentSize = size;
            RecalculatePrice();
        }
Esempio n. 6
0
        public void RefreshRecipes()
        {
            this.IngredientsCollection.Clear();
            this.RecipesCollection.Clear();
            this.OrderedPizzasCollection.Clear();
            this.Ingredients.Clear();

            Worker.EnqueueTask(new WorkerTask((args) =>
            {
                try
                {
                    using (var proxy = new WorkChannel())
                    {
                        return proxy.GetRecipeTabData(new PizzaNetCommon.Requests.EmptyRequest
                        {
                            Login = ClientConfig.CurrentUser.Email,
                            Password = ClientConfig.CurrentUser.Password
                        });
                    }
                    //using (var db = new PizzaUnitOfWork())
                    //{
                    //    return db.inTransaction(uof =>
                    //    {
                    //        Console.WriteLine("LoadDataStart");
                    //        var result = new Trio<IEnumerable<Recipe>, PizzaNetDataModel.Model.Size[], IEnumerable<Ingredient>>
                    //        {
                    //            First = uof.Db.Recipies.FindAllEagerly(),
                    //            Second = uof.Db.Sizes.FindAll().ToArray(),
                    //            Third = uof.Db.Ingredients.FindAll()
                    //        };

                    //        Console.WriteLine("after query");

                    //        Console.WriteLine("Result is null: {0}", result == null);

                    //        return result;
                    //    });
                    //}
                }
                catch (Exception exc)
                {
                    return exc;
                }
            }, (s, args) =>
            {
                if (args.Result is Exception)
                {
                    Utils.HandleException(args.Result as Exception);
                    return;
                }
                var result = args.Result as TrioResponse<List<RecipeDTO>, List<SizeDTO>, List<OrderIngredientDTO>>;
                if (result == null)
                {
                    Utils.showExclamation(Utils.Messages.RECIPES_REFRESH_FAILED);
                    return;
                }
                if (result.Second.Count != 3) throw new Exception(INVALID_SIZES_COUNT);
                foreach (var item in result.First)
                {
                    var rc = new RecipeControl();
                    rc.Recipe = item;
                    rc.RecalculatePrices(result.Second.ToArray());
                    RecipesCollection.Add(rc);
                    Console.WriteLine(item.Name);
                }
                foreach (var item in result.Third)
                {
                    var row = new IngredientsRow(item, 0, result.Second[0]);
                    row.PropertyChanged += row_PropertyChanged;
                    IngredientsCollection.Add(row);
                    Ingredients.Add(item);
                }
                // MODIFIED Tag uses now dependency property
                SmallSize = result.Second[0];
                MedSize = result.Second[1];
                GreatSize = result.Second[2];
                CurrentSizeValue = result.Second[0];
            }));
        }
 public void Update(SizeDTO[] sizes)
 {
     NotifyPropertyChanged("Recipe");
     RecalculatePrices(sizes);
 }
 public void RecalculatePrices(SizeDTO[] sizes)
 {
     Prices = PriceCalculator.GetPrices(Recipe, sizes);
 }