Esempio n. 1
0
        //public virtual List<DayOfWeek> ScheduledDays { get; set; }
        public void AddBlockDay(BlockDay day)
        {
            var existDay = ScheduledDays.Where(d => d.Day == day.Day).FirstOrDefault();

            if (existDay != null)
            {
                existDay.StartTime = day.StartTime;
                existDay.EndTime = day.EndTime;
            }
            else
            {
                ScheduledDays.Add(day);
            }
        }
Esempio n. 2
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                var block = new Block
                {
                    Name = collection.Get("Name"),
                    Description = collection.Get("Description"),
                    IsActive = string.Compare(collection.Get("IsActive"), "false") == 0 ? false : true
                };

                DateTime start, end;

                if (!DateTime.TryParse(collection.Get("StartDate"), out start) || !DateTime.TryParse(collection.Get("EndDate"), out end))
                {
                    ModelState.AddModelError("", "Start date and End date must be dates with the format [dd/mm/yyyy].");
                    FillDropDowns();
                    return View(block);
                }

                block.StartDate = start;
                block.EndDate = end;

                if (start > end)
                {
                    ModelState.AddModelError("", "The end date must be later than the start date.");
                    FillDropDowns();
                    return View(block);
                }

                int teacherId, gradeId;

                if (!int.TryParse(collection.Get("teacherId"), out teacherId) || !int.TryParse(collection.Get("gradeId"), out gradeId))
                {
                    ModelState.AddModelError("", "The selected choices for Teacher and/or Grade are not correct.");
                    FillDropDowns();
                    return View(block);
                }

                if (gradeId == 0 || teacherId == 0)
                {
                    ModelState.AddModelError("", "The selected choices for Teacher and/or Grade are not correct.");
                    FillDropDowns();
                    return View(block);
                }

                if (Conversor.ConvertToBool(collection.Get("chkSunday")))
                {
                    var day = new BlockDay();
                    if (!Conversor.ConvertToDateTime(collection.Get("startSunday"), day.StartTime) || !Conversor.ConvertToDateTime(collection.Get("startSunday"), day.EndTime))
                    {
                        ModelState.AddModelError("", "The times for Sunday are incorrect.");
                        FillDropDowns();
                        return View(block);
                    }
                }

                //var teacher = repository.GetTeacher(teacherId);
                //var grade = repository.GetGradeLevel(gradeId);

                //if (teacher == null || grade == null)
                //{
                //    ModelState.AddModelError("", "The selected choices for Teacher and/or Grade are not correct.");
                //    FillDropDowns();
                //    return View(block);
                //}

                //block.Teacher = teacher;
                //block.Grade = grade;
                block.TeacherId = teacherId;
                block.GradeLevelId = gradeId;

                bRepository.SaveBlock(block);

                return RedirectToAction("Index");
            }
            catch
            {
                FillDropDowns();
                return View();
            }
        }