Beispiel #1
0
        public ActionResult Create(EventForViewModel dto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    dto.Categories = _context.Categories.ToList();
                    return(RedirectToAction("EventForm"));
                }

                var evnt = new Event
                {
                    OrganizerId = User.Identity.GetUserId(),
                    DateTime    = dto.GetDateTime(),
                    CategoryId  = dto.Category,
                    Vanue       = dto.Vanue,
                    Name        = dto.Name
                };

                _context.Events.Add(evnt);
                _context.SaveChanges();

                return(RedirectToAction("mine", "events"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #2
0
        public ActionResult Update(EventForViewModel dto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    dto.Categories = _context.Categories.ToList();
                    return(RedirectToAction("EventForm"));
                }
                var userId = User.Identity.GetUserId();
                var evnt   = _context.Events
                             .Include(g => g.Attendaces.Select(a => a.Attendee))
                             .Single(g => g.Id == dto.Id && g.OrganizerId == userId);
                evnt.Name       = dto.Name;
                evnt.Vanue      = dto.Vanue;
                evnt.DateTime   = dto.GetDateTime();
                evnt.CategoryId = dto.Category;

                evnt.Modify(dto.GetDateTime(), dto.Vanue, dto.Category);
                _context.SaveChanges();

                return(RedirectToAction("mine", "events"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #3
0
        public ActionResult Create()
        {
            var viewModel = new EventForViewModel
            {
                Categories = _context.Categories.ToList(),
                Heading    = "Add A New Event"
            };

            return(View("EventForm", viewModel));
        }
Beispiel #4
0
        // GET: Events/Edit/5
        public ActionResult Edit(int id)
        {
            var userId = User.Identity.GetUserId();
            var gig    = _context.Events.Single(g => g.Id == id && g.OrganizerId == userId);



            var viewModel = new EventForViewModel
            {
                Categories = _context.Categories.ToList(),
                Id         = gig.Id,
                Name       = gig.Name,
                Vanue      = gig.Vanue,
                Date       = gig.DateTime.ToString("dd MMM yyyy"),
                Time       = gig.DateTime.ToString("HH:mm"),
                Category   = gig.CategoryId,
                Heading    = "Edit A Event"
            };

            return(View("EventForm", viewModel));
        }