Пример #1
0
        public IActionResult DeleteDojoAct(int dojoact_id)
        {
            int user_id = HttpContext.Session.GetInt32("UserId").GetValueOrDefault();

            if (user_id == 0)
            {
                return(View("Index"));
            }
            DojoAct thisDojoAct = dbContext.DojoActs
                                  .FirstOrDefault(w => w.DojoActId == dojoact_id);

            dbContext.Remove(thisDojoAct);
            dbContext.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }
Пример #2
0
        public IActionResult Join(int dojoact_id)
        {
            int user_id = HttpContext.Session.GetInt32("UserId").GetValueOrDefault();

            if (user_id == 0)
            {
                return(View("Index"));
            }
            UserDojoAct newAssoc = new UserDojoAct();

            newAssoc.UserId    = user_id;
            newAssoc.DojoActId = dojoact_id;

            // Check for time conflicts
            List <UserDojoAct> myAlreadyJoined = dbContext.UserDojoActs
                                                 .Include(ua => ua.DojoAct)
                                                 .Include(ua => ua.User)
                                                 .Where(ua => ua.UserId == user_id)
                                                 .ToList();
            DojoAct thisDojoAct = dbContext.DojoActs
                                  .FirstOrDefault(d => d.DojoActId == dojoact_id);

            foreach (UserDojoAct j in myAlreadyJoined)
            {
                DateTime jActEndTime      = j.DojoAct.StartDateTime.AddMinutes(j.DojoAct.Duration);
                DateTime thisActStartTime = thisDojoAct.StartDateTime;
                if (jActEndTime > thisActStartTime)
                {
                    DashboardWrap newView = new DashboardWrap();
                    newView.User = dbContext.Users
                                   .Include(u => u.AllDojoActs)
                                   .ThenInclude(ua => ua.DojoAct)
                                   .FirstOrDefault(u => u.UserId == user_id);
                    // Only display current activities
                    List <DojoAct> AllPastPresent = dbContext.DojoActs
                                                    .Include(d => d.AllUsers)
                                                    .Include(d => d.Creator)
                                                    .OrderBy(d => d.StartDateTime)
                                                    .ToList();
                    List <DojoAct> OnlyCurrentActs = new List <DojoAct>();
                    foreach (DojoAct i in AllPastPresent)
                    {
                        int act_date   = i.StartDateTime.Year * 1000 + i.StartDateTime.DayOfYear;
                        int today_date = DateTime.Now.Year * 1000 + DateTime.Now.DayOfYear;
                        if (act_date > today_date)
                        {
                            OnlyCurrentActs.Add(i);
                        }
                    }
                    newView.AllDojoActs   = OnlyCurrentActs;
                    newView.TimeConflicts = "Cannot join activity due to time conflict with another one of your activities.";
                    System.Console.WriteLine("**********************************************************");
                    System.Console.WriteLine(j.DojoAct.StartDateTime.AddMinutes(j.DojoAct.Duration).Ticks);
                    System.Console.WriteLine(thisDojoAct.StartDateTime.Ticks);
                    return(View("Dashboard", newView));
                }
            }
            dbContext.Add(newAssoc);
            dbContext.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }