Example #1
0
        public string AddNewClass(Course Item1, List <DayTime> listDayTime)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);
            var numErr = errors.Count();

            if (ModelState.IsValid || (numErr == 1 && listDayTime.Count == 0))
            {
                if (checkStartDateLessEndDate(Item1.StartDate, Item1.EndDate))
                {
                    ExcludeDate.excludeDate(Item1.StartDate);
                    Item1.SDay   = ExcludeDate.Day;
                    Item1.SMonth = ExcludeDate.Month;
                    Item1.SYear  = ExcludeDate.Year;
                    ExcludeDate.excludeDate(Item1.EndDate);
                    Item1.EDay   = ExcludeDate.Day;
                    Item1.EMonth = ExcludeDate.Month;
                    Item1.EYear  = ExcludeDate.Year;
                    if (Item1.Id != 0)
                    {
                        reposCourse.Update(Item1);
                        foreach (var item in listDayTime)
                        {
                            var findDateTime = db.DayTimes.Where(item2 => item2.Day == item.Day && item2.StartTime ==
                                                                 item.StartTime && item2.EndTime == item.EndTime &&
                                                                 item2.CourseId == Item1.Id).FirstOrDefault();
                            if (findDateTime == null)
                            {
                                item.CourseId = Item1.Id;
                                db.DayTimes.Add(item);
                            }
                        }
                        if (Course.checkDateTimeCourse(listDayTime, Item1.SalonId))
                        {
                            db.SaveChanges();
                            return("TRUE");
                        }
                    }
                    else
                    {
                        if (Course.checkDateTimeCourse(listDayTime, Item1.SalonId))
                        {
                            ApplicationDbContext courseDb = new ApplicationDbContext();
                            courseDb.Courses.Add(Item1);
                            courseDb.SaveChanges();

                            var trainer = courseDb.Users.Where(item => item.Id == Item1.TrainerId).First();
                            Item1.ApplicationUsers = new List <ApplicationUser>();
                            Item1.TrainerStatus    = CoachAcceptance.Pending;
                            Item1.ApplicationUsers.Add(trainer);
                            courseDb.SaveChanges();

                            foreach (var item in listDayTime)
                            {
                                item.CourseId = Item1.Id;
                                db.DayTimes.Add(item);
                            }
                            db.SaveChanges();

                            if (Item1.TrainerId != null)
                            {
                                Message message   = new Message();
                                var     MajorInfo = reposMajor.Read(Item1.MajorId);
                                message.Caption = "دعوت به مربیگری در کلاس " + MajorInfo.Name;
                                message.Text    = "مربی گرامی کلاسی در ترم آینده برای شما در نظر گرفته شده است." +
                                                  "لطفا جهت اطلاع بیشتر از این کلاس و مشخصات آن و جهت  <b>پذیرش</b> این کلاس بخش کلاس های داشبورد خود را کنترل فرمایید.";
                                var adminId = HttpContext.User.Identity.GetUserId();
                                message.SenderId   = adminId;
                                message.RecieverId = Item1.TrainerId;
                                message.DateTime   = DateTime.Now;
                                reposMessage.Create(message);
                            }
                            return("TRUE");
                        }
                        else
                        {
                            return("در بازه های زمانی این کلاس با کلاسی دیگر تداخل وجو دارد");
                        }
                    }
                }
                return("تاریخ پایان کلاس باید بیشتر از تاریخ شروع باشد");
            }
            IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);

            return("در اعتبارسنجی داده ها خطایی پیش آمد لطفا داده های ورودی را بررسی کنید");
        }
Example #2
0
        public List <DayTime> setStatusFieldOfCourse(List <DayTime> dayTimes, string classStartTime, string classEndTime)
        {
            PersianCalendar pc           = new PersianCalendar();
            DateTime        dateTime1    = DateTime.Parse(classStartTime);
            DateTime        dateTime2    = DateTime.Parse(classEndTime);
            int             year         = pc.GetYear(DateTime.Now);
            int             month        = pc.GetMonth(DateTime.Now);
            int             day          = pc.GetDayOfMonth(DateTime.Now);
            List <DayTime>  dayTimeList  = dayTimes;
            List <DayTime>  dayTimeList2 = new List <DayTime>();

            ExcludeDate.excludeDate(classStartTime);
            int SDay   = ExcludeDate.Day;
            int SMonth = ExcludeDate.Month;
            int SYear  = ExcludeDate.Year;

            ExcludeDate.excludeDate(classEndTime);
            int EDay   = ExcludeDate.Day;
            int EMonth = ExcludeDate.Month;
            int EYear  = ExcludeDate.Year;

            foreach (var item in dayTimeList.ToList())
            {
                DateTime startTime = DateTime.Parse(item.Courses.SYear + "/" + item.Courses.SMonth + "/" + item.Courses.SDay);
                DateTime endTime   = DateTime.Parse(item.Courses.EYear + "/" + item.Courses.EMonth + "/" + item.Courses.EDay);
                if (startTime <= dateTime1 && endTime > dateTime2)
                {
                    dayTimeList2.Add(item);
                }
                else if (startTime <= dateTime1 && endTime >= dateTime1 && endTime <= dateTime2)
                {
                    dayTimeList2.Add(item);
                }
                else if (startTime >= dateTime1 && endTime >= dateTime2 && startTime <= endTime)
                {
                    dayTimeList2.Add(item);
                }

                //state1
                //if (item.SYear >= SYear && item.EYear <= EYear)
                //{
                //    if (item.SMonth >= SMonth && item.EMonth <= EMonth)
                //    {
                //        if (item.SDay >= SDay && item.EYear <= EDay)
                //        {
                //            item.Status = Status.Active;
                //            courses.Add(item);

                //        }
                //        else if (item.SDay <= SDay && item.EDay >= EDay)
                //        {
                //            item.Status = Status.Active;
                //            courses.Add(item);
                //        }
                //        else if(item.SDay<=EDay && item.EDay>=EDay && item.SDay>=SDay)
                //        {
                //            item.Status = Status.Pending;
                //            courses.Add(item);

                //        }
                //        else if (item.SDay <= EDay && item.EDay >= EDay && item.SDay <= SDay)
                //        {
                //            item.Status = Status.Active;
                //            courses.Add(item);

                //        }
                //    }
                //    else if(item.SMonth<SMonth && item.EMonth>EMonth)
                //    {
                //        item.Status = Status.Active;
                //        courses.Add(item);
                //    }


                //}
                //else if(item.SYear<SYear && item.EYear<=EYear)
                //{
                //    if()
                //}
            }
            return(dayTimeList2);
        }