// GET: UserDemographics/Create
 public ActionResult Create()
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         ViewBag.Hobbies = context.Hobbies.Where(x => x.IsActive)
                           .OrderBy(x => x.Name).ToList();
     }
     return(View("Manage", new UserDemographics()));
 }
Exemplo n.º 2
0
        // GET: UserDemographics
        public ActionResult Index()
        {
            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                var list = context.UserDemographics.OrderBy(x => x.Birthdate).ToList();


                return(View(list));
            }
        }
 public ActionResult Details(int id)
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         Item item = context.Items.FirstOrDefault(x => x.Id == id);
         UserHelper.AddUserVisit(id, context);
         context.SaveChanges();
         return(View(item));
     }
 }
Exemplo n.º 4
0
        public ActionResult Details(int id)
        {
            Guid UserID = UserHelper.GetUserId();

            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();
            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                var order = context.Orders.Include(p => p.OrderDetails.Select(c => c.Item)).FirstOrDefault(x => x.Id == id && x.UserId == UserID);
                return(View(order));
            }
        }
 // GET: UserDemographics
 public ActionResult Index()
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         var list = context.UserDemographics.OrderBy(x => x.Birthdate).ToList();
         list.Add(new UserDemographics {
             Birthdate = new DateTime(2000, 6, 8)
         });
         return(View(list));
     }
 }
Exemplo n.º 6
0
        private ShoppingCartSummary GetShoppingCartSummary(RentMyWroxContext context)
        {
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var cartList = context.ShoppingCarts.Where(x => x.UserId == UserID);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Item.Cost);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
 public ActionResult NonAdminSnippet()
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         Notification note = context.Notifications
                             .Where(x => x.DisplayStartDate <= DateTime.Now &&
                                    x.DisplayEndDate >= DateTime.Now &&
                                    !x.IsAdminOnly)
                             .OrderByDescending(x => x.CreateDate)
                             .FirstOrDefault();
         return(PartialView("_Notification", note));
     }
 }
Exemplo n.º 8
0
        public static void AddUserVisit(int itemId, RentMyWroxContext context)
        {
            Guid userId = GetUserId();

            context.UserVisits.RemoveRange(context.UserVisits.Where(x => x.UserId == userId && x.ItemId == itemId));

            context.UserVisits.Add(new UserVisit
            {
                ItemId    = itemId,
                UserId    = userId,
                VisitDate = DateTime.Now
            });
        }
Exemplo n.º 9
0
 public ActionResult Recent()
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         Guid newUserId   = UserHelper.GetUserId();
         var  recentItems = (from uv in context.UserVisits
                             join item in context.Items on uv.ItemId equals item.Id
                             where uv.UserId == newUserId
                             orderby uv.VisitDate descending
                             select item as Item).Take(3).ToList();
         context.SaveChanges();
         return(PartialView("_RecentItems", recentItems));
     }
 }
        public void DetailsView1_InsertItem()
        {
            Hobby hobby = new Hobby();

            TryUpdateModel(hobby);
            if (ModelState.IsValid)
            {
                using (RentMyWroxContext context = new RentMyWroxContext())
                {
                    context.Hobbies.Add(hobby);
                    context.SaveChanges();
                }
            }
        }
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (RentMyWroxContext context = new RentMyWroxContext())
         {
             var item = context.UserDemographics.FirstOrDefault(x => x.Id == id);
             TryUpdateModel(item);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(View());
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                Notification note = context.Notifications
                                    .Where(x => x.IsAdminOnly &&
                                           x.DisplayStartDate <= DateTime.Now &&
                                           x.DisplayEndDate >= DateTime.Now)
                                    .OrderByDescending(y => y.CreateDate)
                                    .FirstOrDefault();

                if (note != null)
                {
                    NotificationTitle.Text  = note.Title;
                    NotificationDetail.Text = note.Details;
                }
            }
        }
 public ActionResult Edit(int id, FormCollection collection)
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         var item = context.UserDemographics.FirstOrDefault(x => x.Id == id);
         TryUpdateModel(item);
         var ids = Request.Form.GetValues("HobbyIds");
         item.Hobbies = context.Hobbies.Where(x => ids.Contains(x.Id.ToString())).ToList();
         var validationErrors = context.GetValidationErrors();
         if (validationErrors.Count() == 0)
         {
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.ServerValidationErrors = ConvertValidationErrorsToString(validationErrors);
         return(View("Manage", item));
     }
 }
 public ActionResult Create(UserDemographics obj)
 {
     try
     {
         using (RentMyWroxContext context = new RentMyWroxContext())
         {
             var ids = Request.Form.GetValues("HobbyIds");
             obj.Hobbies = context.Hobbies
                           .Where(x => ids.Contains(x.Id.ToString())).ToList();
             context.UserDemographics.Add(obj);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(View());
     }
 }
        private ShoppingCartSummary GetShoppingCartSummary(RentMyWroxContext context)
        {
            Guid UserID = UserHelper.GetUserId();
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var appUser = UserHelper.GetApplicationUser();

            if (appUser != null)
            {
                summary.UserDisplayName = string.Format("{0} {1}", appUser.FirstName, appUser.LastName);
            }

            var cartList = context.ShoppingCarts.Where(x => x.UserId == UserID);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Item.Cost);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
 public ActionResult Create(UserDemographics obj)
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         var ids = Request.Form.GetValues("HobbyIds");
         if (ids != null)
         {
             obj.Hobbies = context.Hobbies.Where(x => ids.Contains(x.Id.ToString())).ToList();
         }
         context.UserDemographics.Add(obj);
         var validationErrors = context.GetValidationErrors();
         if (validationErrors.Count() == 0)
         {
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.ServerValidationErrors = ConvertValidationErrorsToString(validationErrors);
         return(View("Manage", obj));
     }
 }
        protected void SaveItem_Clicked(object sender, EventArgs e)
        {
            Item item;

            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                if (itemId == 0)
                {
                    item = new Item();
                    UpdateItem(item);
                    context.Items.Add(item);
                }
                else
                {
                    item = context.Items.FirstOrDefault(x => x.Id == itemId);
                    UpdateItem(item);
                }
                context.SaveChanges();
            }
            Response.Redirect("~/admin/ItemList");
        }
        public ActionResult AddToCart(int id)
        {
            Guid UserID = UserHelper.GetUserId();

            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                Item addedItem = context.Items.FirstOrDefault(x => x.Id == id);

                // now that we know it is a valid ID
                if (addedItem != null)
                {
                    // Check to see if this item was already added
                    var sameItemInShoppingCart = context.ShoppingCarts
                                                 .FirstOrDefault(x => x.Item.Id == id && x.UserId == UserID);
                    if (sameItemInShoppingCart == null)
                    {
                        // if not already in cart then add it
                        ShoppingCart sc = new ShoppingCart
                        {
                            Item      = addedItem,
                            UserId    = UserID,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        // increment the quantity of the existing shopping cart item
                        sameItemInShoppingCart.Quantity++;
                    }

                    UserHelper.AddUserVisit(id, context);

                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);
                return(PartialView("_ShoppingCartSummary", summary));
            }
        }
Exemplo n.º 19
0
        public ActionResult Index(int pageNumber = 1, int pageQty = 5, string sortExp = "name_asc")
        {
            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                // set most of the items needed on the client-side
                ViewBag.PageSize       = pageQty;
                ViewBag.PageNumber     = pageNumber;
                ViewBag.SortExpression = sortExp;

                var items = from i in context.Items
                            where i.IsAvailable
                            select i;

                // setting this here to get the count of the filtered list
                ViewBag.ItemCount = items.Count();

                switch (sortExp)
                {
                case "name_asc":
                    items = items.OrderBy(i => i.Name);
                    break;

                case "name_desc":
                    items = items.OrderByDescending(i => i.Name);
                    break;

                case "cost_asc":
                    items = items.OrderBy(i => i.Cost);
                    break;

                case "cost_desc":
                    items = items.OrderByDescending(i => i.Cost);
                    break;
                }

                items = items.Skip((pageNumber - 1) * pageQty).Take(pageQty);
                return(View(items.ToList()));
            }
        }
Exemplo n.º 20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IList <string> segments = Request.GetFriendlyUrlSegments();

            itemId = 0;
            if (segments != null && segments.Count > 0)
            {
                int.TryParse(segments[0], out itemId);
            }

            if (!IsPostBack && itemId != 0)
            {
                using (RentMyWroxContext context = new RentMyWroxContext())
                {
                    var item = context.Items.FirstOrDefault(x => x.Id == itemId);
                    tbAcquiredDate.Text = item.DateAcquired.ToShortDateString();
                    tbCost.Text         = item.Cost.ToString();
                    tbDescription.Text  = item.Description;
                    tbItemNumber.Text   = item.ItemNumber;
                    tbName.Text         = item.Name;
                }
            }
        }