Exemplo n.º 1
0
        public ActionResult Create()
        {
            var model = new PartyFormViewModel
            {
                PartyTypes = _context.PartyTypes.ToList(),
                Heading    = "Opret Fest"
            };

            return(View("PartyForm", model));
        }
Exemplo n.º 2
0
        public ActionResult Create(PartyFormViewModel viewModel)
        {
            var hostId = User.Identity.GetUserId();
            var party  = new Party
            {
                HostId      = hostId,
                Title       = viewModel.Title,
                Description = viewModel.Description,
                Venue       = viewModel.Venue,
                DateTime    = DateTime.Parse(string.Format("{0} {1}", viewModel.Date, viewModel.Time))
            };

            _context.Parties.Add(party);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            var userId = User.Identity.GetUserId();
            var party  = _context.Parties.Single(p => p.Id == id && p.UserId == userId);

            var model = new PartyFormViewModel
            {
                Heading    = "Rediger Fest",
                Id         = party.Id,
                PartyTypes = _context.PartyTypes.ToList(),
                Date       = party.DateTime.ToString("d MMM yyyy"),
                Time       = party.DateTime.ToString("HH:mm"),
                PartyType  = party.PartyTypeId,
                Location   = party.Location
            };

            return(View("PartyForm", model));
        }
Exemplo n.º 4
0
        public ActionResult Update(PartyFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.PartyTypes = _context.PartyTypes.ToList();
                return(View("PartyForm", model));
            }

            var userId = User.Identity.GetUserId();
            var party  = _context.Parties
                         .Include(p => p.Attendances.Select(a => a.Attendee))
                         .Single(p => p.Id == model.Id && p.UserId == userId);

            party.Modify(model.GetDateTime(), model.Location, model.PartyType);

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Parties"));
        }
Exemplo n.º 5
0
        public ActionResult Create(PartyFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.PartyTypes = _context.PartyTypes.ToList();
                return(View("PartyForm", model));
            }

            var party = new Party
            {
                UserId      = User.Identity.GetUserId(),
                DateTime    = model.GetDateTime(),
                PartyTypeId = model.PartyType,
                Location    = model.Location
            };

            _context.Parties.Add(party);
            _context.SaveChanges();

            return(RedirectToAction("Mine", "Parties"));
        }