// // GET: /EventManager/Create public ActionResult Create() { ViewBag.Categories = storeDB.Categories.OrderBy(g => g.Name).ToList(); ViewBag.Places = storeDB.Places.OrderBy(a => a.Name).ToList(); var theEvent = new Event(); return View(theEvent); }
public void AddToCart(Event theEvent) { // Get the matching cart and event instances var cartItem = storeDB.Carts.SingleOrDefault(c => c.CartId == ShoppingCartId && c.EventId == theEvent.EventId); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new Cart { EventId = theEvent.EventId, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; storeDB.Carts.Add(cartItem); } else { // If the item does exist in the cart, then add one to the quantity cartItem.Count++; } // Save changes storeDB.SaveChanges(); }
public ActionResult Create(Event theEvent) { var image = WebImage.GetImageFromRequest(); var filename = ""; if (ModelState.IsValid) { if (image != null) { image.Resize(87, 87); filename = Path.GetFileName(image.FileName); string sourceName = filename; string fileExt = ""; int i; if ((i = filename.IndexOf(".")) != -1) { /* Here we read s substring of filename starting from ".", which will be the file extension */ fileExt = filename.Substring(i); //Here we read the filename without its extension filename = filename.Substring(0, i); } DateTime time = DateTime.Now; // Use current time string format = "dd-MM-yyyy hh-mm-ss"; // Use this format string sdf = time.ToString(format); //Here we add the date time stamp to the file name filename = sdf + "_" + filename; //Here we put the file name parts together and create a new filename with the //directory path and the extension filename = filename + fileExt; theEvent.EventPlaceUrl = "/Content/Images/" + filename; image.Save(Path.Combine("~/Content/Images/", filename)); filename = Path.Combine("~/Content/Images/", filename); var ImageUrl = Url.Content(filename); } else { theEvent.EventPlaceUrl = "/Content/Images/placeholder.gif"; } //Save event storeDB.Events.Add(theEvent); storeDB.SaveChanges(); return RedirectToAction("Index"); } // Invalid – redisplay with errors ViewBag.Categories = storeDB.Categories.OrderBy(g => g.Name).ToList(); ViewBag.Places = storeDB.Places.OrderBy(a => a.Name).ToList(); return View(theEvent); }