public ActionResult Create(HellViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a new event.
                Event e = new Event();
                e.Brief = model.CreateViewModel.Brief;
                e.Detailed = model.CreateViewModel.Detailed;
                e.Visibility = model.CreateViewModel.Visibility;
                e.Address = model.CreateViewModel.Address;
                e.Latitude = model.CreateViewModel.Latitude;
                e.Longitude = model.CreateViewModel.Longitude;
                e.StartTime = model.CreateViewModel.StartTime;
                e.ModificationState = ModificationState.Added;
                e.OwnerId = User.Identity.GetUserId();
                eventUoW.Events.Attach(e);

                // Create a share link for this event.
                InviteLink link = new InviteLink();
                link.Event = e;
                link.LinkGUID = Guid.NewGuid().ToString();
                link.OneTimeUse = false;
                link.ModificationState = ModificationState.Added;
                eventUoW.InviteLinks.Attach(link);

                // Save the changes.
                eventUoW.Save();

                return RedirectToAction("Details", "Event", new { id = e.Id });
            }

            return View();
        }
Beispiel #2
0
        public ActionResult Generate(int eventId)
        {
            Event e = eventUoW.Events.GetEventByID(eventId);
            if (e == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            if (User.Identity.GetUserId() != e.OwnerId)
            {
                return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
            }

            Guid guid = Guid.NewGuid();
            InviteLink link = new InviteLink { EventId = eventId, LinkGUID = guid.ToString(), OneTimeUse = true, ModificationState = ModificationState.Added };
            eventUoW.InviteLinks.Attach(link);
            eventUoW.Save();

            UrlHelper urlHelper = new UrlHelper(HttpContext.Request.RequestContext);
            string url = urlHelper.Action("Details", "Event", new { id = eventId, guid = guid.ToString() }, urlHelper.RequestContext.HttpContext.Request.Url.Scheme);

            return Json(new { url = url });
        }
 public void Remove(InviteLink link)
 {
     context.InviteLinks.Remove(link);
 }
 public void Attach(InviteLink entity)
 {
     context.InviteLinks.Add(entity);
     ContextStateHelper.ApplyStateChanges(context);
 }