Example #1
0
        public ActionResult SubmitChapterTeaching([Bind(Include = "ChapterId,chapterTeachings")] ChapterDateAndTeaching model)
        {
            if (!LoginStatus())
            {
                return(RedirectToAction("Login", "Admins", null));
            }

            if (ModelState.IsValid)
            {
                if (model.chapterTeachings != null)
                {
                    foreach (var item in model.chapterTeachings)
                    {
                        bool Exists = _db.ChapterTeachings.Any(d => d.ChapterId == model.ChapterId && d.TeachingTypeId == item.TeachingTypeId);

                        ChapterTeaching model2 = new ChapterTeaching()
                        {
                            Chapter           = item.Chapter,
                            ChapterId         = model.ChapterId,
                            ChapterTeachingId = item.ChapterTeachingId,
                            MaxVal            = item.Status == true ? item.MaxVal : 0,
                            MinVal            = item.Status == true ? item.MinVal : 0,
                            OrderId           = item.OrderId,
                            Status            = item.Status,
                            TeachingType      = _db.TeachingTypes.Find(item.TeachingTypeId),
                            TeachingTypeId    = item.TeachingTypeId
                        };

                        if (model2.MinVal <= model2.MaxVal)
                        {
                            if (!Exists)
                            {
                                _db.ChapterTeachings.Add(model2);
                            }
                            else
                            {
                                _db.Entry(model2).State = EntityState.Modified;
                            }
                        }
                        else
                        {
                            return(Json("Error: cause of some wrong information feeded."));
                        }
                        _db.SaveChanges();
                    }
                    return(Json(""));
                }
                else
                {
                    return(Json("Model is not valid."));
                }
            }
            else
            {
                return(Json("Model is not valid."));
            }
        }
Example #2
0
        public ActionResult SettingsDisplay([Bind(Include = "ChapterId,CStartDate,CEndDate,chapterTeachings")] ChapterDateAndTeaching model)
        {
            if (!LoginStatus())
            {
                return(RedirectToAction("Login", "Admins", null));
            }

            if (ModelState.IsValid)
            {
                if (model.CStartDate >= model.CEndDate)
                {
                    return(Json("start date should be before end date"));
                }

                ChapterDate chapterDate = new ChapterDate()
                {
                    ChapterId  = model.ChapterId,
                    CStartDate = model.CStartDate,
                    CEndDate   = model.CEndDate,
                    Chapter    = model.Chapter,
                };

                bool Exists = _db.ChapterDates.Any(d => d.ChapterId == model.ChapterId);
                if (!Exists)
                {
                    _db.ChapterDates.Add(chapterDate);
                    _db.SaveChanges();
                }
                else
                {
                    _db.Entry(chapterDate).State = EntityState.Modified;
                    _db.SaveChanges();
                }
                return(Json(""));
            }
            else
            {
                return(Json("Model is not valid."));
            }
        }
Example #3
0
        //Chapter Subject
        public ActionResult SettingsDisplay(int?id, bool checkChapterDate = true)
        {
            if (!LoginStatus())
            {
                return(RedirectToAction("Login", "Admins", null));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ChapterDate chapterDate = _db.ChapterDates.Find(id);

            chapterDate = (chapterDate == null) ? new ChapterDate() : chapterDate;

            ChapterDateAndTeaching model = new ChapterDateAndTeaching()
            {
                chapterTeachings = new List <ChapterTeaching>()
            };


            if (chapterDate.ChapterId == 0 || checkChapterDate != true)
            {
                model.ChapterId        = (long)id;
                model.CheckChapterDate = true;
                model.Chapter          = _db.Chapters.Find(id);
                return(View(model));
            }
            else
            {
                model.CEndDate         = chapterDate.CEndDate;
                model.CStartDate       = chapterDate.CStartDate;
                model.Chapter          = _db.Chapters.Find(id);
                model.ChapterId        = chapterDate.ChapterId;
                model.CheckChapterDate = false;
                model.chapterTeachings = new List <ChapterTeaching>();

                List <ChapterTeaching> lstChapterTeaching = new List <ChapterTeaching>();

                lstChapterTeaching = _db.ChapterTeachings.Where(d => d.ChapterId == id).ToList();

                var teachingType = _db.TeachingTypes.OrderBy(d => d.OrderId).ToList();

                foreach (var item in teachingType)
                {
                    ChapterTeaching findVal = new ChapterTeaching();
                    findVal = lstChapterTeaching.Find(d => d.TeachingTypeId == item.TeachingTypeId);

                    ChapterTeaching chapterTeaching = new ChapterTeaching()
                    {
                        OrderId           = findVal != null ? findVal.OrderId : item.OrderId,
                        MinVal            = findVal != null ? findVal.MinVal : 0,
                        MaxVal            = findVal != null ? findVal.MaxVal : 0,
                        ChapterId         = (long)id,
                        TeachingTypeId    = item.TeachingTypeId,
                        ChapterTeachingId = findVal != null ? findVal.ChapterTeachingId : 0,
                        Chapter           = model.Chapter,
                        TeachingType      = item,
                        Status            = findVal != null ? findVal.Status : false
                    };
                    model.chapterTeachings.Add(chapterTeaching);
                }
                model.ChapterId = (long)id;
                model.Chapter   = _db.Chapters.Find(id);
                return(View(model));
            }
        }