Example #1
0
        public ActionResult Create(AuctionItemCreateViewModel v)
        {
            DateTime minDate = DateTime.Now;
            DateTime maxDate = minDate.AddDays(7);

            bool isEndDateValid = v.EndDateTime > minDate && v.EndDateTime < maxDate;

            if (ModelState.IsValid && isEndDateValid)
            {
                List <ItemImage> images = new List <ItemImage>();

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFileBase file = Request.Files[i];

                    if (file.ContentLength > 0 && file.ContentLength <= 4194304 &&
                        (file.ContentType == "image/gif" || file.ContentType == "image/jpeg" || file.ContentType == "image/png"))
                    {
                        images.Add(new ItemImage(BlobStorageHelper.UploadBlob(User.Identity.GetUserId(), Guid.NewGuid().ToString(), file)));
                    }
                }

                var a = new AuctionItem(v, CategoryDB.GetCategoryByID(db, v.SelectedCategory), ApplicationUserDB.GetUserByID(db, User.Identity.GetUserId()), images);
                AuctionItemDB.Create(db, a);
                return(RedirectToAction("Index", "AuctionItem"));
            }

            if (!isEndDateValid)
            {
                ModelState.AddModelError("EndDateTime", $"Auction item end time must be between {minDate} and {maxDate}");
            }

            return(View(v));
        }
Example #2
0
 public ActionResult Update(AuctionItemCreateViewModel v)
 {
     if (ModelState.IsValid)
     {
         var a = new AuctionItem(v, CategoryDB.GetCategoryByID(db, v.SelectedCategory), ApplicationUserDB.GetUserByID(db, User.Identity.GetUserId()));
         if (AuctionItemDB.Update(db, a))
         {
             return(RedirectToAction("Index", "AuctionItem"));
         }
         ModelState.AddModelError("UpdateFailed", "Currently logged in user is not the owner of this item.");
     }
     return(View(v));
 }