示例#1
0
        public EventViewModel(EventViewModel route)
        {
            Date = route.Date;
            Description = route.Description;
            DateCreated = route.DateCreated;
            DateModified = route.DateModified;
            Title = route.Title;
            Time = route.Time;
            EventRoutes = route.EventRoutes;

            Location = route.Location;
        }
示例#2
0
 public HomeViewModel(EventViewModel[] evnts,RouteViewModel[] routes)
 {
     Events = evnts;
     Routes = routes;
 }
示例#3
0
        public IActionResult CreateEvent()
        {
            ListModelResponse<Route> routeResponse = _routeContext.GetUserRoutes(_userManager.GetUserId(User));
            if (routeResponse.DidError == true || routeResponse == null)
            {
                if (routeResponse == null)
                    return View("Error");
                Error er = new Error(routeResponse.ErrorMessage);
                return View("Error");
            }
            if (routeResponse.Model.Any())
            {
                ViewBag.UserRoutes = GetRoutes(null);

            }
            else
            {
                ViewBag.UserRoutes = null;
            }
            ListModelResponse<Club> clubResponse = _clubContext.GetUserClubs(_userManager.GetUserId(User));
            if (clubResponse.DidError == true || routeResponse == null)
            {
                if (routeResponse == null)
                    return View("Error");
                Error er = new Error(routeResponse.ErrorMessage);
                return View("Error");
            }
            if (clubResponse.Model.Any())
            {
                ViewBag.UserClubs = GetClubs(null);
            }
            else
            {
                ViewBag.UserClubs = null;
            }
            string eventCookie = HttpContext.Request.Cookies["NewEvent"];
            EventViewModel model = new EventViewModel();
            if (eventCookie != null)
            {
                model = eventCookie.FromJson<EventViewModel>();
            }

            return View(model);
        }
示例#4
0
        public IActionResult CreateEvent(EventViewModel model, int[] RouteId)
        {
            if (ModelState.IsValid)
            {
                if (model.EventRoutes == null)
                {
                    model.EventRoutes = new List<EventRouteViewModel>();
                }
                foreach (int id in RouteId)
                {
                    SingleModelResponse<Route> routeResponse = _routeContext.GetRoute(id);
                    if (routeResponse.DidError == true || routeResponse == null)
                    {
                        if (routeResponse == null)
                            return View("Error");
                        Error er = new Error(routeResponse.ErrorMessage);
                        return View("Error");
                    }

                    model.EventRoutes.Add(routeResponse.Model.ToEventRouteViewModel());
                }
                if (model.ClubId != 0)
                {
                    SingleModelResponse<Club> clubResponse = _clubContext.GetClub(model.ClubId);
                    if (clubResponse.DidError == true || clubResponse == null)
                    {
                        if (clubResponse == null)
                            return View("Error");
                        Error er = new Error(clubResponse.ErrorMessage);
                        return View("Error");
                    }
                    model.ClubName = clubResponse.Model.Name;
                }
                //example of using cookie
                var CookieOption = new CookieOptions();
                CookieOption.Expires = DateTime.Now.AddMinutes(5);
                CookieOption.HttpOnly = true;

                //set cookie
                HttpContext.Response.Cookies.Append("NewEvent", model.ToJson(), CookieOption);

                return RedirectToAction("FinalizeEvent");
            }
            else
            {
                return View(model);
            }
        }
示例#5
0
        public SingleModelResponse<EventViewModel> GetEvent(int eventId)
        {
            string getUrl = EventUri + "GetEvent?eventId="+eventId;
            var evnt = GetSingleContent<Event>(getUrl);
            List<EventRouteViewModel> routes = new List<EventRouteViewModel>();
            if (evnt.Model.EventRoute.Count>0)
            {
                foreach (EventRoute rou in evnt.Model.EventRoute)
                {
                    EventRouteViewModel newRoute = new EventRouteViewModel
                    {
                        Title = rou.Title,
                        DateAdded = rou.DateAdded,
                        RouteId = rou.RouteID,
                        EventRouteId = rou.EventRouteID,
                        DateModified = rou.DateAdded,
                        Distance = rou.Distance,
                        Description = rou.Description,
                        EventId = rou.EventID
                    };
                    routes.Add(newRoute);
                }
            }
            EventViewModel ConvertedEvent = new EventViewModel
            {
                EventId = evnt.Model.EventId,
                Date = evnt.Model.Date,
                DateCreated = evnt.Model.DateCreated,
                DateModified = evnt.Model.DateModified,
                Description = evnt.Model.Description,
                UserID = evnt.Model.UserID,
                Location = evnt.Model.Location,
                Time = evnt.Model.Time,
                Title = evnt.Model.Title,
                EventRoutes = routes,

            };
            if(evnt.Model.ClubID>0)
            {
                ConvertedEvent.ClubId = evnt.Model.ClubID;
                ConvertedEvent.ClubName = evnt.Model.Club.Name;
            }
            SingleModelResponse<EventViewModel> model = new SingleModelResponse<EventViewModel>
            {
                DidError = evnt.DidError,
                Message = evnt.Message,
                ErrorMessage = evnt.ErrorMessage,
                Model = ConvertedEvent
            };
            return model;
        }
示例#6
0
        public SingleModelResponse<Event> UpdateEvent(EventViewModel evnt)
        {
            string saveUrl = EventUri + "Update/EditEvent";
            List<EventRoute> newRoutes = new List<EventRoute>();
            char numLet = 'A';
            foreach (EventRouteViewModel evntRoute in evnt.EventRoutes)
            {
                EventRoute route = new EventRoute(DateTime.Now.ToString());
                route.Title = evnt.Title+' '+numLet;
                numLet++;
                route.Description = evnt.Description;
                route.Distance = evntRoute.Distance;
                route.RouteID = evntRoute.RouteId;
                route.EventID = evnt.EventId;
                newRoutes.Add(route);
            }

            var newEvent = new Event
            {
                EventId = evnt.EventId,
                Date = evnt.Date,
                Time = evnt.Time,
                Description = evnt.Description,
                DateCreated = evnt.DateCreated,
                DateModified = DateTime.Now.ToString(),
                Location = evnt.Location,
                Title = evnt.Title,
                EventRoute = newRoutes
            };
            var updatedEvent = PutContent(saveUrl, newEvent);
            return updatedEvent;
        }
示例#7
0
        public SingleModelResponse<Event> SaveEvent(EventViewModel evnt)
        {
            string saveUrl = EventUri + "SaveEvent";
            List<EventRoute> newRoutes = new List<EventRoute>();
            foreach (EventRouteViewModel evntRoute in evnt.EventRoutes)
            {
                EventRoute route = new EventRoute(DateTime.Now.ToString());
                route.Title = evntRoute.Title;
                route.Description = evntRoute.Description;
                route.RouteID = evntRoute.RouteId;
                route.Distance = evntRoute.Distance;
                route.EventID = evnt.EventId;
                newRoutes.Add(route);
            }

            var newEvent = new Event
            {
                UserID = evnt.UserID,
                Date = evnt.Date,
                ClubID = evnt.ClubId,
                Time = evnt.Time,
                DateCreated=DateTime.Now.ToString(),
                Description = evnt.Description,
                Location = evnt.Location,
                Title = evnt.Title,
                EventRoute = newRoutes
            };
            var createdEvent = PostContent(saveUrl, newEvent);
            return createdEvent;
        }