Esempio n. 1
0
        public ActionResult DrinkName(FormCollection collection, int barId)
        {
            using (ServiceHelper serviceHelper = new ServiceHelper())
            {
                DrinkServiceClient drinkProxy = serviceHelper.GetDrinkServiceClient();
                try
                {
                    string name            = Convert.ToString(collection["DrinkName"]);
                    bool   drinkNameExists = drinkProxy.CheckDrinkName(name);
                    if (drinkNameExists)
                    {
                        string message = "Drinken eksisterer allerede.";
                        return(RedirectToAction("Index", new { barId = barId, message = message }));
                    }

                    Session["createDrink"] = new DrinkIngredientViewModel();

                    ((DrinkIngredientViewModel)Session["createDrink"]).DrinkName = name;
                    ((DrinkIngredientViewModel)Session["createDrink"]).BarId     = barId;

                    return(RedirectToAction("DrinkIngredient"));
                }
                catch
                {
                    string message = "Der skete desværre en fejl.";
                    return(RedirectToAction("Index", new { barId = barId, message = message }));
                }
            }
        }
Esempio n. 2
0
 //Disposer alel clienter og null them
 //
 public void Dispose()
 {
     _barClient      = null;
     _drinkClient    = null;
     _orderClient    = null;
     _customerClient = null;
 }
Esempio n. 3
0
        public ActionResult DrinkDecription(FormCollection collection)
        {
            using (ServiceHelper serviceHelper = new ServiceHelper())
            {
                DrinkServiceClient drinkProxy = serviceHelper.GetDrinkServiceClient();
                try
                {
                    DrinkServiceReference.Drink drink = new DrinkServiceReference.Drink();
                    drink.Ingredients = ((DrinkIngredientViewModel)Session["createDrink"]).QuantifiedIngredients.ToList();
                    drink.Names       = new List <string> {
                        ((DrinkIngredientViewModel)Session["createDrink"]).DrinkName
                    };
                    drink.Recipe = Convert.ToString(collection["Recipe"]);
                    drinkProxy.CreateDrink(drink);

                    ViewBag.barId = ((DrinkIngredientViewModel)Session["createDrink"]).BarId;
                    string message = "Drinken er nu oprettet.";
                    return(RedirectToAction("Index", new { barId = ViewBag.barId, message = message }));
                }
                catch
                {
                    return(View());
                }
            }
        }
Esempio n. 4
0
 public ActionResult DrinkIngredient()
 {
     using (ServiceHelper serviceHelper = new ServiceHelper())
     {
         DrinkServiceClient       drinkProxy = serviceHelper.GetDrinkServiceClient();
         DrinkIngredientViewModel drinkIngredientViewModel = new DrinkIngredientViewModel();
         drinkIngredientViewModel.Ingredients  = drinkProxy.FindAllIngredients().ToList();
         drinkIngredientViewModel.Measurements = drinkProxy.FindAllMeasurements().ToList();
         return(View(drinkIngredientViewModel));
     }
 }
Esempio n. 5
0
        public ActionResult AddToCart(int drinkid, int barid, string name, string ingredients)
        {
            using (ServiceHelper serviceHelper = new ServiceHelper())
            {
                DrinkServiceClient drinkProxy = serviceHelper.GetDrinkServiceClient();
                OrderServiceClient orderProxy = serviceHelper.GetOrderServiceClient();
                bool   success = orderProxy.DecrementStock(drinkid, barid);
                string message;
                if (success)
                {
                    double price = drinkProxy.FindDrinkPriceById(drinkid, barid);
                    message = $"Drinken er købt til: {price} kr.";
                    if (Session["shoppingcart"] == null)
                    {
                        Session["shoppingcart"] = new List <OrderDrinkViewModel>();
                    }
                    List <OrderDrinkViewModel> list        = (List <OrderDrinkViewModel>)Session["shoppingcart"];
                    List <OrderDrinkViewModel> drinkIdList = list.Where(x => x.DrinkId == drinkid).ToList();
                    if (!drinkIdList.Any())
                    {
                        OrderDrinkViewModel drink = new OrderDrinkViewModel();
                        drink.Names       = new List <string>();
                        drink.BarId       = barid;
                        drink.DrinkId     = drinkid;
                        drink.Ingredients = ingredients;
                        drink.Names.Add(name);
                        drink.Subtotal = price;
                        drink.Quantity = 1;
                        ((List <OrderDrinkViewModel>)Session["shoppingcart"]).Add(drink);
                    }
                    else
                    {
                        if (!drinkIdList.First().Names.Contains(name))
                        {
                            drinkIdList.First().Names.Add(name);
                        }
                        drinkIdList.First().Subtotal += price;
                        drinkIdList.First().Quantity++;
                    }


                    return(RedirectToAction("index", "drink", new { barId = barid, message = message }));
                }
                else
                {
                    message = "drinken er desværre lige blevet udsolgt :(";
                    return(RedirectToAction("index", "drink", new { barId = barid, message = message }));
                }
            }
        }
Esempio n. 6
0
        public DrinkServiceClient GetDrinkServiceClient()
        {
            //In case session ran out
            if (AuthHelper.CurrentUser == null && _drinkClient != null)
            {
                (_drinkClient as IDisposable).Dispose();
                _drinkClient = null;
            }

            if (AuthHelper.CurrentUser != null && _drinkClient == null)
            {
                _drinkClient = new DrinkServiceClient("drinkServiceHttps");
                _drinkClient.ClientCredentials.UserName.UserName = AuthHelper.CurrentUser.Username;
                _drinkClient.ClientCredentials.UserName.Password = AuthHelper.CurrentUser.Password;
            }
            return(_drinkClient);
        }
Esempio n. 7
0
        public ActionResult Index(int barId, string message)
        {
            using (ServiceHelper serviceHelper = new ServiceHelper())
            {
                DrinkServiceClient drinkProxy = serviceHelper.GetDrinkServiceClient();
                BarServiceClient   barProxy   = serviceHelper.GetBarServiceClient();
                //Ambiguous reference her
                BarServiceRerefence.Bar   foundBar = barProxy.Find(barId);
                DrinkServiceReference.Bar bar      = new DrinkServiceReference.Bar();
                bar.ID   = foundBar.ID;
                bar.Name = foundBar.Name;

                Dictionary <int, DrinkViewModel> drinks = drinkProxy.GetAvailableDrinks(bar);

                ViewBag.barId   = barId;
                ViewBag.BarName = bar.Name;
                ViewBag.Message = message;


                return(View(drinks));
            }
        }
Esempio n. 8
0
        public ActionResult DrinkIngredient(FormCollection collection)
        {
            using (ServiceHelper serviceHelper = new ServiceHelper())
            {
                DrinkServiceClient drinkProxy = serviceHelper.GetDrinkServiceClient();
                try
                {
                    double quantity = Convert.ToDouble(collection["Quantity"]);

                    int ingredientId  = Convert.ToInt32(collection["ddlIngredient"]);
                    int measurementId = Convert.ToInt32(collection["ddlMeasurement"]);

                    DrinkServiceReference.Ingredient ingredient = new DrinkServiceReference.Ingredient();
                    ingredient = drinkProxy.FindIngredient(ingredientId);

                    DrinkServiceReference.Measurement measurement = new DrinkServiceReference.Measurement();
                    measurement = drinkProxy.FindMeasurement(measurementId);

                    DrinkServiceReference.QuantifiedIngredient quantifiedIngredient = new DrinkServiceReference.QuantifiedIngredient();
                    quantifiedIngredient.Ingredient  = ingredient;
                    quantifiedIngredient.Measurement = measurement;
                    quantifiedIngredient.Quantity    = quantity;

                    if (((DrinkIngredientViewModel)Session["createDrink"]).QuantifiedIngredients == null)
                    {
                        ((DrinkIngredientViewModel)Session["createDrink"]).QuantifiedIngredients = new List <DrinkServiceReference.QuantifiedIngredient>();
                    }

                    ((DrinkIngredientViewModel)Session["createDrink"]).QuantifiedIngredients.Add(quantifiedIngredient);

                    return(RedirectToAction("DrinkIngredient"));
                }
                catch
                {
                    return(View());
                }
            }
        }