예제 #1
0
        public ActionResult Add()
        {
            CookieViewModel cvm = new CookieViewModel {
                SuccessMessage = "Cookie Created Sucessfully"
            };
            HttpCookie cookie = new HttpCookie("Color", "Red");

            cookie.Expires = DateTime.Now.AddDays(7);
            Response.Cookies.Add(cookie);
            return(View(cvm));
        }
        public ActionResult Cookies()
        {
            var cookieViewModel = new CookieViewModel
            {
                ImprovementUrl         = _settings.CookieImprovementUrl.ToString(),
                GoogleUrl              = _settings.CookieGoogleUrl.ToString(),
                ApplicationInsightsUrl = _settings.CookieApplicationInsightsUrl.ToString(),
                AboutUrl          = _settings.CookieAboutUrl.ToString(),
                SurveyProviderUrl = _settings.SurveyProviderUrl.ToString()
            };

            return(View(cookieViewModel));
        }
예제 #3
0
        public ActionResult Display()
        {
            CookieViewModel cvm    = new CookieViewModel();
            HttpCookie      cookie = HttpContext.Request.Cookies.Get("Color");

            if (cookie != null)
            {
                cvm.CookieName    = cookie.Name;
                cvm.CookieValue   = cookie.Value;
                cvm.CookieExpires = cookie.Expires;
            }
            else
            {
                cvm.ErrorMessage = "Cookie Not Found";
            }

            return(View(cvm));
        }
예제 #4
0
        public async Task <IActionResult> Order(CookieViewModel cookieVM)
        {
            if (ModelState.IsValid)
            {
                Order order = new Order();

                _context.Order.Add(order);
                _context.SaveChanges();
                List <Cookie> cookies = await _context.Cookie.Where(c => c.OutOfStock == false).ToListAsync();

                CookieOrderViewModel cookieOrderVM = new CookieOrderViewModel
                {
                    Cookies      = cookies,
                    CookieOrders = new List <CookieOrder>(),
                    OrderId      = order.OrderId
                };
                for (int cookieCount = 0; cookieCount < cookies.Count; cookieCount++)
                {
                    if (cookieVM.Cookies[cookieCount].Amount > 0)
                    {
                        CookieOrder cookieOrder = new CookieOrder
                        {
                            Cookie        = cookies[cookieCount],
                            OrderId       = order.OrderId,
                            CookieId      = cookies[cookieCount].CookieId,
                            NumberOfBoxes = cookieVM.Cookies[cookieCount].Amount
                        };
                        _context.CookieOrder.Add(cookieOrder);
                        cookieOrderVM.CookieOrders.Add(cookieOrder);

                        order.TotalAmountDue = order.TotalAmountDue + (cookieVM.Cookies[cookieCount].Amount * cookies[cookieCount].CostPerBox);
                    }
                }
                _context.Order.Update(order);
                _context.SaveChanges();

                cookieOrderVM.TotalDue = order.TotalAmountDue;

                return(View("CookieOrder", cookieOrderVM));
            }
            CookieViewModel cookieErrorVM = new CookieViewModel(await _context.Cookie.ToListAsync());

            return(View("Index", cookieErrorVM));
        }
        public ActionResult <CookieViewModel> CreateCookie()
        {
            string        key   = "cookie_test1";
            string        value = DateTime.Now.ToString();
            CookieOptions c     = new CookieOptions();

            c.Expires  = DateTime.Now.AddMinutes(1);
            c.HttpOnly = !IsInDevelopment(Data.StartupData.MyWebHostEnv);
            c.Secure   = true;
            c.SameSite = SameSiteMode.Strict;
            Response.Cookies.Append(key, value, c);

            CookieViewModel model = new CookieViewModel
            {
                CookieExpirationDate = c.Expires.ToString()
            };

            return(View(nameof(Index), model));
        }
        public IActionResult ChooseYourCookie(CookieViewModel model)
        {
            if (model.Type.Equals("Chocolate Chip"))
            {
                return(View("GoodCookies", new CookieSelectionViewModel
                {
                    Type = model.Type,
                    Flavor = "Yummy"
                }));
            }
            else if (model.Type.Equals("Oatmeal Raisin"))
            {
                return(View("GoodCookies", new CookieSelectionViewModel
                {
                    Type = model.Type,
                    Flavor = "THE BEST"
                }));
            }

            return(View("BadCookies"));
        }
예제 #7
0
        public async Task <IActionResult> Index()
        {
            CookieViewModel cookieVM = new CookieViewModel(await _context.Cookie.ToListAsync());

            return(View(cookieVM));
        }