Example #1
0
        public async Task <IActionResult> EditLecture(EditLectureViewModel model)
        {
            if (ModelState.IsValid)
            {
                var classSectionObj = await _tPClassReposiroty.GetClassSectionById(model.Class_Id, model.Section_Id);

                if (classSectionObj != null)
                {
                    var classSubjectObj = await _tPClassReposiroty.GetClassSubjectById(classSectionObj.ClassSection_id, model.Subject_Id);

                    if (classSubjectObj != null)
                    {
                        var objLecture = await _LectureRepository.GetLectureById(model.Id);

                        //objLecture.Lecture_Name = model.Lecture_Name;
                        //objLecture.Lecture_Detail = model.Lecture_Detail;
                        //objLecture.LecturePost_Date = model.LecturePost_Date;
                        //objLecture.Teacher_Id = HttpContext.Session.GetInt32("UserId") ?? 1;
                        //objLecture.ClassSubject_Id = classSubjectObj.ClassSubject_Id;

                        Lecture Lecture = new Lecture();
                        Lecture.Lecture_Id       = model.Id;
                        Lecture.Lecture_Name     = model.Lecture_Name;
                        Lecture.Lecture_Detail   = model.Lecture_Detail;
                        Lecture.LecturePost_Date = model.LecturePost_Date.ToString("yyyyMMdd");
                        Lecture.Teacher_Id       = HttpContext.Session.GetInt32("UserId") ?? 1;
                        Lecture.ClassSubject_Id  = classSubjectObj.ClassSubject_Id;



                        if (model.Lecture_File != null)
                        {
                            if (model.ExistingFilePath != null)
                            {
                                string filePath = Path.Combine(_hostingEnvironment.WebRootPath,
                                                               "Lectures", model.ExistingFilePath);
                                System.IO.File.Delete(filePath);
                            }

                            string uniqueFileName = Utility.ProcessUploadedFile(model.Lecture_File, _hostingEnvironment, "Lectures");

                            //objLecture.Lecture_File = uniqueFileName;
                            Lecture.Lecture_File = uniqueFileName;
                        }
                        else
                        {
                            Lecture.Lecture_File = objLecture.ExistingFilePath;
                        }

                        int result = await _LectureRepository.UpdateLecture(Lecture);

                        if (result == 1)
                        {
                            TempData["Success"] = "Lecture Updated Successfully";
                            return(RedirectToAction("Index", "lecture", new { area = "teachers" }));
                        }
                        else
                        {
                            TempData["Error"] = "Updating Lecture Failed ";
                            return(RedirectToAction("Index", "lecture", new { area = "teachers" }));
                        }
                    }
                    else
                    {
                        TempData["Error"] = "Class And Section Dont Have Seleceted Subject";
                        return(RedirectToAction("Index", "lecture", new { area = "teachers" }));
                    }
                }
                else
                {
                    TempData["Error"] = "Class With Section Didn't Find";
                    return(RedirectToAction("Index", "lecture", new { area = "teachers" }));
                }
            }

            return(View());
        }
Example #2
0
        public async Task <IActionResult> EditLecture(int id)
        {
            var objLecture = await _LectureRepository.GetLectureById(id);

            EditLectureViewModel model = new EditLectureViewModel
            {
                //Id = objLecture.Lecture_Id,
                Id             = objLecture.Id,
                Lecture_Name   = objLecture.Lecture_Name,
                Lecture_Detail = objLecture.Lecture_Detail,
                //ExistingFilePath = objLecture.Lecture_File,
                ExistingFilePath = objLecture.ExistingFilePath,
                LecturePost_Date = objLecture.LecturePost_Date,
                Class_Id         = objLecture.Class_Id,
                Section_Id       = objLecture.Section_Id,
                Subject_Id       = objLecture.Subject_Id
            };

            List <SelectListItem> classList = new List <SelectListItem>();

            classList.Insert(0, new SelectListItem()
            {
                Value = "-1", Text = "--Select--"
            });
            var objClassSecSub = _LectureRepository.GetAllClassSectionByTeacherId(HttpContext.Session.GetInt32("UserId") ?? 1).ToList();

            foreach (var lstclass in objClassSecSub)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstclass.Class_Name,
                    Value = lstclass.Class_Id.ToString(),
                };

                classList.Add(selectListItem);
            }
            ViewBag.ClassList = classList;


            List <SelectListItem> sectionList = new List <SelectListItem>();

            sectionList.Insert(0, new SelectListItem()
            {
                Value = "-1", Text = "--Select--"
            });
            foreach (var lstSection in objClassSecSub)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstSection.Section_Name,
                    Value = lstSection.Section_Id.ToString(),
                };

                sectionList.Add(selectListItem);
            }
            ViewBag.SectionList = sectionList;

            List <SelectListItem> subjectList = new List <SelectListItem>();

            subjectList.Insert(0, new SelectListItem()
            {
                Value = "-1", Text = "--Select--"
            });
            var objSubject = _LectureRepository.GetAllSubjectByTeacherId(HttpContext.Session.GetInt32("UserId") ?? 1).ToList();

            foreach (var lstSubject in objSubject)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstSubject.Subject_Name,
                    Value = lstSubject.Subject_Id.ToString(),
                };

                subjectList.Add(selectListItem);
            }
            ViewBag.SubjectList = subjectList;

            return(View(model));
        }