Ejemplo n.º 1
0
        public ActionResult Edit()
        {
            CommonDataService cds = new CommonDataService();

            CommonModel cm = new CommonModel();

            cm = cds.GenerateCommonModel();
            Session["FaceBook"]      = cm.FaceBook;
            Session["Twitter"]       = cm.Twitter;
            Session["Youtube"]       = cm.Youtube;
            Session["Instagram"]     = cm.Instagram;
            Session["PhoneNumber"]   = cm.PhoneNumber;
            Session["Email"]         = cm.Email;
            Session["ShoppingHours"] = cm.ShoppingHours;
            PromoDataService dataService = new PromoDataService();
            PromoViewModel   viewModel   = new PromoViewModel();

            try
            {
                viewModel.PromoModel = dataService.GeneratePromoModel();
                return(View(viewModel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dataService = null;
                viewModel   = null;
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Entry(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return(View(model: "Missing code."));
            }

            Guid guidToken;

            if (!Guid.TryParse(token, out guidToken))
            {
                return(View(model: "Invalid code."));
            }

            PromoViewModel promo = await PromoService.GetPromo(guidToken);

            if (promo == null)
            {
                return(View(model: "The code you tried to use is invalid."));
            }
            else if (!promo.Active)
            {
                return(View(model: "Promo has expired. Please contact Center for Global Studies for help."));
            }

            HttpCookie cookie = new HttpCookie("promo", token.ToString());

            cookie.Expires = DateTime.Now.AddHours(8);
            HttpContext.Response.SetCookie(cookie);

            return(RedirectToAction("Form"));
        }
Ejemplo n.º 3
0
        private PromoViewModel GetAdminSpecialsModel(PromoViewModel model)
        {
            var repo = PromoRepositoryFactory.GetRepository();

            model.Promos = repo.GetAll();

            return(model);
        }
Ejemplo n.º 4
0
        public ActionResult Specials()
        {
            var model = new PromoViewModel();

            model = GetAdminSpecialsModel(model);

            return(View(model));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="promo">May be <see langword="null"/>.</param>
        /// <returns></returns>
        private PromoViewModel PrepPromo(PromoViewModel promo)
        {
            if (promo != null)
            {
                promo.CanDelete = promo.TotalStudents == 0;
            }

            return(promo);
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Info(int id)
        {
            PromoViewModel promo = await PromoService.GetPromo(id);

            if (promo == null)
            {
                string message = string.Format("Promo ID {0} not found", id);
                MvcApplication.LogException(new ArgumentException(message, nameof(id)));
                return(RedirectToAction("NotFound", "Error"));
            }

            promo.Students = await StudentService.FromPromo(promo.Id);

            return(View(promo));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Edit(int id)
        {
            PromoViewModel promo = await PromoService.GetPromo(id);

            if (promo == null)
            {
                string message = string.Format("Promo ID {0} not found", id);
                MvcApplication.LogException(new ArgumentException(message, nameof(id)));
                return(RedirectToAction("NotFound", "Error"));
            }

            PromoEditViewModel model = new PromoEditViewModel()
            {
                Id          = promo.Id,
                Description = promo.Description,
                Active      = promo.Active
            };

            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult Specials(PromoViewModel promo)
        {
            if (Request.IsAuthenticated)
            {
                var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var user    = userMgr.FindByName(User.Identity.Name);
                ViewBag.UserId = user.Id;
            }

            var repo = PromoRepositoryFactory.GetRepository();

            if (ModelState.IsValid)
            {
                try
                {
                    Promo newPromo = new Promo();
                    newPromo.PromotionName        = promo.PromotionName;
                    newPromo.PromotionDescription = promo.PromotionDescription;
                    newPromo.ImageFileName        = promo.ImageFileName;

                    repo.Insert(newPromo);

                    TempData["Message"] = "Promotion added.";
                    return(RedirectToAction("Specials", "Admin"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                promo.Promos = repo.GetAll();
                return(View(promo));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Delete(int id)
        {
            PromoViewModel promo = await PromoService.GetPromo(id);

            if (promo == null)
            {
                return(Json(new GenericResult()
                {
                    Result = false,
                    Message = "Invalid promo code"
                }));
            }

            if (!promo.CanDelete)
            {
                return(Json(new GenericResult()
                {
                    Result = false,
                    Message = "Promo not eligible for deletion"
                }));
            }

            return(Json(await PromoService.Delete(id)));
        }
Ejemplo n.º 10
0
        public async Task <PromoViewModel> GetPromo(Guid token)
        {
            PromoViewModel promo = await PromoRepository.GetPromo(token);

            return(PrepPromo(promo));
        }
Ejemplo n.º 11
0
        public async Task <PromoViewModel> GetPromo(int id)
        {
            PromoViewModel promo = await PromoRepository.GetPromo(id);

            return(PrepPromo(promo));
        }
Ejemplo n.º 12
0
        public ActionResult Edit(PromoViewModel viewModel)
        {
            CommonDataService cds = new CommonDataService();

            CommonModel cm = new CommonModel();

            cm = cds.GenerateCommonModel();
            Session["FaceBook"]      = cm.FaceBook;
            Session["Twitter"]       = cm.Twitter;
            Session["Youtube"]       = cm.Youtube;
            Session["Instagram"]     = cm.Instagram;
            Session["PhoneNumber"]   = cm.PhoneNumber;
            Session["Email"]         = cm.Email;
            Session["ShoppingHours"] = cm.ShoppingHours;
            PromoDataService dataService = new PromoDataService();
            string           promoId     = (string)Request.Form["edit_PromoId"];
            string           imageString = (string)Request.Form["edit_ImageString"];

            try
            {
                if (ModelState.IsValid)
                {
                    WebImage photo       = null;
                    var      newFileName = "";
                    var      imagePath   = "";

                    photo = WebImage.GetImageFromRequest();
                    if (photo != null)
                    {
                        newFileName = Guid.NewGuid().ToString() + "_" +
                                      Path.GetFileName(photo.FileName);
                        imagePath = @"Contents\Images\Promo\" + newFileName;

                        photo.Save(@"~\" + imagePath);
                        viewModel.PromoModel.PromoId     = int.Parse(promoId);
                        viewModel.PromoModel.ImageString = imagePath;
                    }
                    else
                    {
                        viewModel.PromoModel.PromoId     = int.Parse(promoId);
                        viewModel.PromoModel.ImageString = imageString;
                    }

                    dataService.UpdatePromo(viewModel.PromoModel);
                    return(RedirectToAction("Edit", "Promo"));
                }
                else
                {
                    viewModel.PromoModel.PromoId     = int.Parse(promoId);
                    viewModel.PromoModel.ImageString = imageString;
                    return(View(viewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dataService = null;
            }
        }