Ejemplo n.º 1
0
        public ActionResult Create(EventModel newEvent, int categoryId)
        {
            newEvent.Category = _categoryDataAccess.GetCategoryById(categoryId);

            try
            {
                var newId = _eventDataAccess.CreateEvent(newEvent);
                return RedirectToAction("View", "Event", new { id = newId });
            }
            catch
            {
                ViewBag.Error =
                    "There was an error creating the event, please review the fields below and correct any mistakes.";
                var categories = _categoryDataAccess.GetCategories();
                ViewBag.Categories = categories;
                return View(newEvent);
            }
        }
Ejemplo n.º 2
0
        public int CreateEvent(EventModel e)
        {
            using (var db = new EventSignInEntities())
            {
                var newEvent = new Event
                    {
                        Name = e.Name,
                        Description = e.Description,
                        Location = e.Location,
                        Date = e.Date,
                        Category = e.Category.Id,
                    };

                db.Events.Add(newEvent);
                db.SaveChanges();

                return newEvent.Id;
            }
        }