Beispiel #1
0
        // GET: TimeLine
        public ActionResult Index(int?year)
        {
            /*	On top Current Year to Birth Year
             *
             *      Below Months of Selected Year
             *
             *      With Months, List of Locations
             *
             *      Button to Details
             */
            if (User.Identity.IsAuthenticated)
            {
                TimeLineViewModal        modal     = new TimeLineViewModal();
                ApplicationDbContext     context   = new ApplicationDbContext();
                BM4.Code.CommonFunctions functions = new Code.CommonFunctions();
                UserProfile user = functions.CurrentUserProfile(User);

                modal.years = new List <int>();
                for (int i = user.DateOfBirth.Year; i <= DateTime.Now.Year; i++)
                {
                    modal.years.Add(i);
                }
                modal.years.Reverse();
                modal.firstYear = modal.years.First();
                modal.lastYear  = modal.years.Last();
                if (year.HasValue)
                {
                    modal.currentYear = modal.years[modal.years.IndexOf(year.Value)];
                }
                else
                {
                    modal.currentYear = modal.years[0];
                }
                modal.months = BM4.Code.Constants.MONTHNAMESHORT.Select(t => t + " " + modal.currentYear);

                modal.monthEvents = context.UserEvents
                                    //.Include("Locations,MainLocations,LocationTypes")
                                    //.Include(x => x.)
                                    .Where(t => t.UserId == user.UserId && t.StartingDate.Year <= modal.currentYear && t.EndingDate.Year >= modal.currentYear)
                                    .Select(x => new MonthEvents()
                {
                    startDate          = x.StartingDate,
                    endDate            = x.EndingDate,
                    locationId         = x.LocationId,
                    location           = x.Location.Text1 + ", " + x.Location.MainLocation.Text2,
                    locationsubheading = x.Location.MainLocation.Text3 + "<br/>" +
                                         x.Location.MainLocation.Text4 + "<br/>" +
                                         x.Location.MainLocation.City
                }).ToList();

                return(View(modal));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Beispiel #2
0
        public BaseController()
        {
            if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                BM4.Code.CommonFunctions functions = new Code.CommonFunctions();
                UserProfile profile = functions.CurrentUserProfile(System.Web.HttpContext.Current.User);

                ViewBag.UserTitle  = string.IsNullOrEmpty(profile.Title) ? profile.UserName : profile.Title;
                ViewBag.ProfilePic = string.IsNullOrEmpty(profile.ProfilePic) ? "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSDgTNKTeE985pM29w_MVlLv6Q6zXuK8qHKq4O0pcB_aWH4JbQV&s" : profile.ProfilePic;
            }
        }
Beispiel #3
0
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                Code.CommonFunctions functions   = new Code.CommonFunctions();
                UserProfile          userProfile = functions.CurrentUserProfile(User);
                ApplicationDbContext context     = new ApplicationDbContext();
                string userId = User.Identity.GetUserId();
                List <UserEventViewModel> userEvents = context.UserEvents.Where(t => t.UserId == userId)
                                                       .Select(x => new UserEventViewModel()
                {
                    EventId      = x.UserEventId,
                    Location1    = x.Location.Text1,
                    Location2    = x.Location.MainLocation.Text2,
                    Location3    = x.Location.MainLocation.Text3,
                    Location4    = x.Location.MainLocation.Text4,
                    City         = x.Location.MainLocation.City,
                    StartingDate = x.StartingDate,
                    EndingDate   = x.EndingDate
                }).OrderByDescending(t => t.StartingDate).ToList();

                if (userProfile.DateOfBirth != null)
                {
                    userEvents.Add(new UserEventViewModel()
                    {
                        StartingDate = userProfile.DateOfBirth,
                        EndingDate   = userProfile.DateOfBirth
                    });
                }
                List <UserEventViewModel> finalEvents = new List <UserEventViewModel>();
                //finalEvents.Add(userEvents.ElementAt(0));
                for (int i = 0; i < userEvents.Count() - 1; i++)
                {
                    finalEvents.Add(userEvents.ElementAt(i));
                    if (userEvents.ElementAt(i + 1).EndingDate < userEvents.ElementAt(i).StartingDate)
                    {
                        finalEvents.Add(new UserEventViewModel()
                        {
                            Location1    = "Where you have been ? Add your life event and connect with your friends.",
                            StartingDate = userEvents.ElementAt(i + 1).EndingDate,
                            EndingDate   = userEvents.ElementAt(i).StartingDate,
                            HasScope     = true
                        });
                    }
                }
                return(View(finalEvents.OrderByDescending(t => t.StartingDate)));
            }
            else
            {
                return(View(new List <UserEventViewModel>()));
            }
        }
Beispiel #4
0
 public ActionResult Index(UserEvent userEvent)
 {
     ViewData["Error"] = "";
     if (User.Identity.IsAuthenticated)
     {
         BM4.Code.CommonFunctions commonFunctions = new Code.CommonFunctions();
         userEvent.UserId = User.Identity.GetUserId(); // commonFunctions.CurrentUserProfile(User).UserId;
         if (!ModelState.IsValid)
         {
             using (ApplicationDbContext contextx = new ApplicationDbContext())
             {
                 var fromCityDatabaseEF = new
                                          SelectList(contextx.MainLocations.Select(t => new SelectListItem()
                 {
                     Text = t.City, Value = t.City
                 }).Distinct().OrderBy(t => t.Text).ToList(), "Value", "Text");
                 ViewData["City"] = fromCityDatabaseEF;
             }
             return(View(userEvent));
         }
         if (userEvent.StartingDate > userEvent.EndingDate)
         {
             using (ApplicationDbContext contextx = new ApplicationDbContext())
             {
                 var fromCityDatabaseEF = new
                                          SelectList(contextx.MainLocations.Select(t => new SelectListItem()
                 {
                     Text = t.City, Value = t.City
                 }).Distinct().OrderBy(t => t.Text).ToList(), "Value", "Text");
                 ViewData["City"] = fromCityDatabaseEF;
             }
             ModelState.AddModelError("InvalidDates", "Start Date should be smaller then End Date");
             return(View(userEvent));
         }
         using (ApplicationDbContext context = new ApplicationDbContext())
         {
             context.UserEvents.Add(userEvent);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }