예제 #1
0
        /// <summary>
        /// Fills the checkout page with data from the user' cart.
        /// </summary>
        /// <returns>The modifed checkout view</returns>
        public ActionResult Checkout()
        {
            UserDataContext udc = new UserDataContext();
            PicturesContext pc = new PicturesContext();
            PictureModel pm = new PictureModel();

            var a = from user in udc.DBUserData
                    where user.Username == User.Identity.Name
                    select user.Order;
            char[] order = a.ToArray().First().ToArray();
            string tempstr = "";
            List<int> orderList = new List<int>();
            for (int i = 0; i < order.Count(); i++)
            {

                if (char.IsNumber(order[i]))
                {

                    string temp = Convert.ToString(order[i]);
                    tempstr += temp;
                }
                else
                {
                    if (tempstr.Length > 0)
                    {
                        orderList.Add(Convert.ToInt32(tempstr));
                        tempstr = "";
                    }

                }
                if (i + 1 == order.Count())
                {
                    orderList.Add(Convert.ToInt32(tempstr));
                }
            }
            List<PictureModel> photoList = new List<PictureModel>();
            foreach (int ID in orderList)
            {
                var photo = from x in pc.Picture
                            where x.Id == ID
                            select x;
                if(photo.Any())
                photoList.Add(photo.ToList().First());
            }
            ViewData["photoList"] = photoList;
            return View("Checkout");
        }
예제 #2
0
        public ActionResult Filter(FormCollection collection)
        {
            PicturesContext pContext = new PicturesContext();
            List<string> aColors = new List<string>();
            List<string> aOrientation = new List<string>();
            List<string> aCategories = new List<string>();
            var pModel = pContext.Picture;

            string sColors = collection["colors"]; // red,yellow
            if (sColors != "")
            {
                aColors = sColors.Split(',').ToList();
            }

            string sOrientation = collection["orientation"]; // a,b
            if (sOrientation != "")
            {
                aOrientation = sOrientation.Split(',').ToList();
            }

            string sCategories = collection["categories"]; // a,b
            if (sCategories != "")
            {
                aCategories = sCategories.Split(',').ToList();
            }

            string sPricerange = collection["priceRange"]; // 20,30
            var aPricerange = sPricerange.Split(',');
            int priceMin = Convert.ToInt32(aPricerange[0]);
            int priceMax = Convert.ToInt32(aPricerange[1]);

            var pictures = from p in pModel
                           where p.Price >= priceMin && p.Price <= priceMax
                           select p;

            string sName = collection["name"];
            if (sName != "")
            {
                pictures = from p in pictures
                           where p.Name.Contains(sName)
                           select p;
            }

            if (sColors != "")
            {
                pictures = from p in pictures
                           where aColors.Contains(p.Color)
                           select p;
            }

            if (sOrientation != "")
            {
                pictures = from p in pictures
                           where aOrientation.Contains(p.Orientation)
                           select p;
            }

            if (sCategories != "")
            {
                pictures = from p in pictures
                           where aCategories.Contains(p.Category)
                           select p;
            }

            var countPictures = pictures.Count();

            if (countPictures == 0)
            {
                return Json(false);
            }
            else
            {
                return Json(pictures);
            }
        }
예제 #3
0
        public ActionResult PhotoToCart(FormCollection collection)
        {
            if (collection["id"].Contains(',') == true)
                collection["id"].Remove(0, 1);
            int id = Convert.ToInt16(collection["id"]);

            // Get photo
            PicturesContext pContext = new PicturesContext();
            PictureModel photo = pContext.Picture.Find(id);

            // Get logged in user
            UserDataContext uContext = new UserDataContext();
            UserData user;
            string userName = User.Identity.Name;
            var a = from x in uContext.DBUserData
                    where x.Username == userName
                    select x;
            if (a.Any())
            {
                user = a.ToList().First();
            }
            else
            {
                return Json("The system was unable to save your order"); ;
            }

            var order = Session["order"];
            if (order == null)
            {
                Session["order"] = id.ToString();
            }
            else
            {
                Session["order"] = order + ", " + id;
            }
            order = Session["order"];

            user.Order = order.ToString();

            try
            {
                uContext.SaveChanges();
            }
            catch (Exception e)
            {
                return Json("The system was unable to save your order");
            }

            return Json(photo);
        }
예제 #4
0
        public ActionResult PhotoInfo(FormCollection collection)
        {
            int id = Convert.ToInt16(collection["id"]);
            PicturesContext pContext = new PicturesContext();
            PictureModel photo = pContext.Picture.Find(id);

            return Json(photo);
        }
예제 #5
0
        public ActionResult OrderPhotos(FormCollection collection)
        {
            PicturesContext pContext = new PicturesContext();

            string sPicturesIds = collection["pictures"];
            string order = collection["order"];

            if (sPicturesIds != "")
            {
                List<string> aPicturesIds = sPicturesIds.Split(',').ToList();
                List<PictureModel> pictures = new List<PictureModel>();

                foreach (string i in aPicturesIds)
                {
                    int lookFor = Convert.ToInt32(i);

                    var picture = from x in pContext.Picture
                                  where x.Id == lookFor
                                  select x;

                    pictures.AddRange(picture);
                }

                IEnumerable<PictureModel> orderedPictures = pictures;

                switch (order)
                {
                    case "newest":
                        orderedPictures = pictures.OrderBy(PictureModel => PictureModel.Id);
                        break;
                    case "nameAZ":
                        orderedPictures = pictures.OrderBy(PictureModel => PictureModel.Name);
                        break;
                    case "nameZA":
                        orderedPictures = pictures.OrderByDescending(PictureModel => PictureModel.Name);
                        break;
                    case "priceLH":
                        orderedPictures = pictures.OrderBy(PictureModel => PictureModel.Price);
                        break;
                    case "priceHL":
                        orderedPictures = pictures.OrderByDescending(PictureModel => PictureModel.Price);
                        break;
                }

                return Json(orderedPictures);
            }

            return Json(false);
        }
예제 #6
0
        public ActionResult GetPhotos(FormCollection collection)
        {
            PicturesContext pContext = new PicturesContext();

            string searchTerm = collection["searchTerm"];
            // If there is a searchterm, look for it
            if (collection["searchTerm"] != "")
            {
                var pictures = from p in pContext.Picture
                               where p.Name.Contains(searchTerm)
                               orderby p.Id descending
                               select p;
                if (pictures.Count() == 0)
                {
                    return Json(false);
                }
                else {
                    return Json(pictures.ToList());
                }
            }
            else
            {
                var pictures = from p in pContext.Picture
                               orderby p.Id descending
                               select p;
                return Json(pictures.ToList());
            }
        }