Example #1
0
        public ActionResult MeetingSchedule()
        {
            DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1();
            int userId     = Convert.ToInt32(Session["UserID"]);
            var getBracnch = db.Users.Where(o => o.UserID == userId).Select(x => x.BranchId).FirstOrDefault();

            var date = DateTime.Now;

            DateTime beginningOfMonth = new DateTime(date.Year, date.Month, 1);

            while (date.Date.AddDays(1).DayOfWeek != CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek)
            {
                date = date.AddDays(1);
            }

            var result = (int)Math.Truncate((double)date.Subtract(beginningOfMonth).TotalDays / 7f) + 1;

            ViewBag.Week = new SelectList(new[] { new { Text = "--Select--", Value = 0 }, new { Text = "1", Value = 1 }, new { Text = "2", Value = 2 } }, "Value", "Text", 0);


            DSRCManagementSystem.Models.MeetingSchedule objmeeting = new DSRCManagementSystem.Models.MeetingSchedule();



            var firstdateofweek = DateTime.Now;
            var cal             = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
            Dictionary <string, DateTime> currentWeek = new Dictionary <string, DateTime>();
            Dictionary <string, DateTime> nextWeek    = new Dictionary <string, DateTime>();

            var weekofYear = cal.GetWeekOfYear(DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Monday);

            firstdateofweek = FirstDateOfWeek(DateTime.Now.Year, weekofYear, CultureInfo.CurrentCulture);
            int i = 0;

            while (i != 12) // skiped weeekend days...
            {
                if (i < 5)
                {
                    currentWeek.Add(firstdateofweek.AddDays(i).DayOfWeek.ToString(), firstdateofweek.AddDays(i).Date);
                }
                else if (i >= 7)
                {
                    nextWeek.Add(firstdateofweek.AddDays(i).DayOfWeek.ToString(), firstdateofweek.AddDays(i).Date);
                }

                i++;
            }

            if (result % 2 == 0)
            {
                List <DSRCManagementSystem.Models.MeetingSchedule> objmail = new List <DSRCManagementSystem.Models.MeetingSchedule>();

                if (getBracnch != 1)
                {
                    objmail = (from metting_schedule in db.MettingSchedules
                               join proj in db.Projects on metting_schedule.ProjectID equals proj.ProjectID

                               join days in db.Master_Days on metting_schedule.Day equals days.Days
                               where proj.ProjectID == 0
                               select new DSRCManagementSystem.Models.MeetingSchedule
                    {
                        Id = metting_schedule.Id,
                        Project = proj.ProjectName,
                        ProjectID = metting_schedule.ProjectID,
                        Day = metting_schedule.Day,
                        DayId = days.Id,
                        Week = metting_schedule.Week ?? 0,
                        Attendees = metting_schedule.Attendees,

                        From = metting_schedule.TimeSlot,
                        To = metting_schedule.EndTime,
                    }).OrderByDescending(x => x.Week).ThenBy(x => x.DayId).ThenBy(x => x.From).ToList();


                    foreach (var meetingSchedule in objmail)
                    {
                        meetingSchedule.Attendees = MeetingScheduleController.GetUserString(db, meetingSchedule.Attendees);
                        if (result % 2 == meetingSchedule.Week / 2)
                        {
                            meetingSchedule.Date = nextWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                        else
                        {
                            meetingSchedule.Date = currentWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                    }
                }
                else
                {
                    objmail = (from metting_schedule in db.MettingSchedules
                               join proj in db.Projects on metting_schedule.ProjectID equals proj.ProjectID

                               join days in db.Master_Days on metting_schedule.Day equals days.Days
                               select new DSRCManagementSystem.Models.MeetingSchedule
                    {
                        Id = metting_schedule.Id,
                        Project = proj.ProjectName,
                        ProjectID = metting_schedule.ProjectID,
                        Day = metting_schedule.Day,
                        DayId = days.Id,
                        Week = metting_schedule.Week ?? 0,
                        Attendees = metting_schedule.Attendees,

                        From = metting_schedule.TimeSlot,
                        To = metting_schedule.EndTime,
                    }).OrderByDescending(x => x.Week).ThenBy(x => x.DayId).ThenBy(x => x.From).ToList();


                    foreach (var meetingSchedule in objmail)
                    {
                        meetingSchedule.Attendees = MeetingScheduleController.GetUserString(db, meetingSchedule.Attendees);
                        if (result % 2 == meetingSchedule.Week / 2)
                        {
                            meetingSchedule.Date = nextWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                        else
                        {
                            meetingSchedule.Date = currentWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                    }
                }
                return(View(objmail));
            }
            else
            {
                List <DSRCManagementSystem.Models.MeetingSchedule> objmail = new List <DSRCManagementSystem.Models.MeetingSchedule>();

                if (getBracnch != 1)
                {
                    objmail = (from metting_schedule in db.MettingSchedules
                               join proj in db.Projects on metting_schedule.ProjectID equals proj.ProjectID

                               join days in db.Master_Days on metting_schedule.Day equals days.Days
                               where proj.ProjectID == 0
                               select new DSRCManagementSystem.Models.MeetingSchedule
                    {
                        Id = metting_schedule.Id,
                        Project = proj.ProjectName,
                        ProjectID = metting_schedule.ProjectID,
                        Day = metting_schedule.Day,
                        DayId = days.Id,
                        Week = metting_schedule.Week ?? 0,
                        Attendees = metting_schedule.Attendees,

                        From = metting_schedule.TimeSlot,
                        To = metting_schedule.EndTime,
                    }).OrderByDescending(x => x.Week).ThenBy(x => x.DayId).ThenBy(x => x.From).ToList();


                    foreach (var meetingSchedule in objmail)
                    {
                        meetingSchedule.Attendees = MeetingScheduleController.GetUserString(db, meetingSchedule.Attendees);
                        if (result % 2 == meetingSchedule.Week / 2)
                        {
                            meetingSchedule.Date = nextWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                        else
                        {
                            meetingSchedule.Date = currentWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                    }
                }
                else
                {
                    objmail = (from metting_schedule in db.MettingSchedules
                               join proj in db.Projects on metting_schedule.ProjectID equals proj.ProjectID

                               join days in db.Master_Days on metting_schedule.Day equals days.Days
                               select new DSRCManagementSystem.Models.MeetingSchedule
                    {
                        Id = metting_schedule.Id,
                        Project = proj.ProjectName,
                        ProjectID = metting_schedule.ProjectID,
                        Day = metting_schedule.Day,
                        DayId = days.Id,
                        Week = metting_schedule.Week ?? 0,
                        Attendees = metting_schedule.Attendees,

                        From = metting_schedule.TimeSlot,
                        To = metting_schedule.EndTime,
                    }).OrderBy(x => x.Week).ThenBy(x => x.DayId).ThenBy(x => x.From).ToList();

                    foreach (var meetingSchedule in objmail)
                    {
                        meetingSchedule.Attendees = MeetingScheduleController.GetUserString(db, meetingSchedule.Attendees);

                        if (result % 2 == meetingSchedule.Week / 2)
                        {
                            meetingSchedule.Date = nextWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                        else
                        {
                            meetingSchedule.Date = currentWeek[meetingSchedule.Day].ToString("dd/MM/yyyy");
                        }
                    }
                }

                return(View(objmail));
            }
        }
Example #2
0
        public ActionResult DeleteFuture(int Id)
        {
            var date = DateTime.Now;

            DateTime beginningOfMonth = new DateTime(date.Year, date.Month, 1);

            while (date.Date.AddDays(1).DayOfWeek != CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek)
            {
                date = date.AddDays(1);
            }

            var result = (int)Math.Truncate((double)date.Subtract(beginningOfMonth).TotalDays / 7f) + 1;


            var firstdateofweek = DateTime.Now;
            var cal             = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
            Dictionary <string, DateTime> currentWeek = new Dictionary <string, DateTime>();
            Dictionary <string, DateTime> nextWeek    = new Dictionary <string, DateTime>();

            var weekofYear = cal.GetWeekOfYear(DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Monday);

            firstdateofweek = MeetingScheduleController.FirstDateOfWeek(DateTime.Now.Year, weekofYear, CultureInfo.CurrentCulture);
            int i = 0;

            while (i != 12) // skiped weeekend days...
            {
                if (i < 5)
                {
                    currentWeek.Add(firstdateofweek.AddDays(i).DayOfWeek.ToString(), firstdateofweek.AddDays(i).Date);
                }
                else if (i >= 7)
                {
                    nextWeek.Add(firstdateofweek.AddDays(i).DayOfWeek.ToString(), firstdateofweek.AddDays(i).Date);
                }

                i++;
            }

            if (result % 2 == 0)
            {
                var objmail = (from metting_schedule in db.MettingSchedules
                               join proj in db.Projects on metting_schedule.ProjectID equals proj.ProjectID

                               join days in db.Master_Days on metting_schedule.Day equals days.Days
                               select new DSRCManagementSystem.Models.MeetingSchedule
                {
                    Id = metting_schedule.Id,
                    Project = proj.ProjectName,
                    ProjectID = metting_schedule.ProjectID,
                    Day = metting_schedule.Day,
                    DayId = days.Id,
                    Week = metting_schedule.Week ?? 0,
                    Attendees = metting_schedule.Attendees,

                    From = metting_schedule.TimeSlot,
                    To = metting_schedule.EndTime,
                }).OrderByDescending(x => x.Week).ThenBy(x => x.DayId).ThenBy(x => x.From).ToList();


                foreach (var meetingSchedule in objmail)
                {
                    if (meetingSchedule.Attendees != null)
                    {
                        var      CDATE = DateTime.Now;
                        DateTime MDATE = new DateTime();

                        if (result % 2 == meetingSchedule.Week / 2)
                        {
                            MDATE = Convert.ToDateTime(nextWeek[meetingSchedule.Day].ToString("dd/MM/yyyy"));
                        }
                        else
                        {
                            MDATE = Convert.ToDateTime(currentWeek[meetingSchedule.Day].ToString("dd/MM/yyyy"));
                        }



                        List <string> results = meetingSchedule.Attendees.Split(new char[] { ',' }).ToList();
                        foreach (var x in results)
                        {
                            int con = Convert.ToInt32(x);
                            if ((con == Id) && (MDATE > CDATE.Date))
                            {
                                List <string> result2 = new List <string>();
                                result2.Add(x);
                                var RE        = results.Except(result2);
                                var ReqToEdit = db.MettingSchedules.FirstOrDefault(o => o.Id == meetingSchedule.Id);
                                ReqToEdit.Attendees = null;
                                db.SaveChanges();
                                if (results.Count > 1)
                                {
                                    string combindedString = string.Join(",", RE.ToArray());
                                    var    ReqToUpdate     = db.MettingSchedules.FirstOrDefault(o => o.Id == meetingSchedule.Id);
                                    ReqToUpdate.Attendees = combindedString;
                                    db.SaveChanges();
                                }
                            }
                        }
                    }

                    ////////////////
                }
            }
            else
            {
                var objmail = (from metting_schedule in db.MettingSchedules
                               join proj in db.Projects on metting_schedule.ProjectID equals proj.ProjectID

                               join days in db.Master_Days on metting_schedule.Day equals days.Days
                               select new DSRCManagementSystem.Models.MeetingSchedule
                {
                    Id = metting_schedule.Id,
                    Project = proj.ProjectName,
                    ProjectID = metting_schedule.ProjectID,
                    Day = metting_schedule.Day,
                    DayId = days.Id,
                    Week = metting_schedule.Week ?? 0,
                    Attendees = metting_schedule.Attendees,

                    From = metting_schedule.TimeSlot,
                    To = metting_schedule.EndTime,
                }).OrderByDescending(x => x.Week).ThenBy(x => x.DayId).ThenBy(x => x.From).ToList();


                foreach (var meetingSchedule in objmail)
                {
                    if (meetingSchedule.Attendees != null)
                    {
                        var      CDATE = DateTime.Now;
                        DateTime MDATE = new DateTime();

                        if (result % 2 == meetingSchedule.Week / 2)
                        {
                            MDATE = Convert.ToDateTime(nextWeek[meetingSchedule.Day].ToString("dd/MM/yyyy"));
                        }
                        else
                        {
                            MDATE = Convert.ToDateTime(currentWeek[meetingSchedule.Day].ToString("dd/MM/yyyy"));
                        }



                        List <string> results = meetingSchedule.Attendees.Split(new char[] { ',' }).ToList();
                        foreach (var x in results)
                        {
                            int con = Convert.ToInt32(x);
                            if ((con == Id) && (MDATE > CDATE.Date))
                            {
                                List <string> result2 = new List <string>();
                                result2.Add(x);
                                var RE        = results.Except(result2);
                                var ReqToEdit = db.MettingSchedules.FirstOrDefault(o => o.Id == meetingSchedule.Id);
                                ReqToEdit.Attendees = null;
                                db.SaveChanges();
                                if (results.Count > 1)
                                {
                                    string combindedString = string.Join(",", RE.ToArray());
                                    var    ReqToUpdate     = db.MettingSchedules.FirstOrDefault(o => o.Id == meetingSchedule.Id);
                                    ReqToUpdate.Attendees = combindedString;
                                    db.SaveChanges();
                                }
                            }
                        }
                    }

                    ////////////////
                }
            }
            return(null);
        }