public ActionResult AddCoursedetails()
        {
            DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1();
            LDCourseModelList             ld = new LDCourseModelList();

            try
            {
                var LevelList      = db.Master_TrainingLevel.ToList();
                var TechList       = db.Master_TrainingTechnology.ToList();
                var InstructorList = db.TrainingInstructors.ToList();

                string[] l = new string[LevelList.Count];
                for (int j = 0; j < LevelList.Count; j++)
                {
                    l[j] = LevelList[j].LevelName;
                }
                string result1 = string.Join("\n", l);
                TempData["res1"] = result1;
                string[] t = new string[TechList.Count];

                for (int k = 0; k < TechList.Count; k++)
                {
                    t[k] = TechList[k].TechnologyName;
                }

                string result2 = string.Join("\n", t);

                TempData["res2"] = result2;
                string[] s = new string[InstructorList.Count];

                for (int i = 0; i < InstructorList.Count; i++)
                {
                    s[i] = InstructorList[i].InstructorName;
                }
                string result = string.Join("\n", s);

                TempData["res"] = result;

                string Filepath = Server.MapPath("~/CourseTemplate/Course1.xlt");
                CellDataWriter1(1, 1, Filepath, "sheet1");

                DSRCManagementSystem.Models.LDCourseModel ObjLD = new DSRCManagementSystem.Models.LDCourseModel();
                ModelState.Clear();
                List <LDCourseModel> ldm = new List <LDCourseModel>();

                LDCourseModel         lModel     = new LDCourseModel();
                List <SelectListItem> LevelList1 = new List <SelectListItem>();
                List <SelectListItem> TechList1  = new List <SelectListItem>();

                foreach (var list in LevelList)
                {
                    LevelList1.Add(new SelectListItem {
                        Text = list.LevelName, Value = Convert.ToString(list.LevelId)
                    });
                }
                lModel.LevelIDList = LevelList1;
                foreach (var list in TechList)
                {
                    TechList1.Add(new SelectListItem {
                        Text = list.TechnologyName, Value = Convert.ToString(list.TechnologyId)
                    });
                }
                lModel.TechIDList = TechList1;

                ViewBag.InstructorIDList = new SelectList(new[] { new TrainingInstructor()
                                                                  {
                                                                      InstructorId = 0, InstructorName = ""
                                                                  } }.Union(InstructorList), "InstructorId", "InstructorName", 0);


                for (int i = 0; i < 10; i++)
                {
                    LDCourseModel lm = new LDCourseModel();
                    lm.Coursename   = "";
                    lm.LevelId      = 0;
                    lm.TechnologyId = 0;
                    lm.InstructorID = 0;
                    lm.Scheduledate = null;
                    ldm.Add(lm);
                }

                ld.ldmlist = ldm;
                ld.LDM     = lModel;
            }
            catch (Exception Ex)
            {
                string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName);
            }
            return(View("AddCoursedetails", ld));
        }
        public ActionResult AddCoursedetails(LDCourseModelList model)
        {
            DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1();
            LDCourseModelList             ld = new LDCourseModelList();

            try
            {
                for (int i = 0; i < model.ldmlist.Count; i++)
                {
                    var LDobj = db.Trainings.CreateObject();
                    if (model.ldmlist[i].TechnologyId != 0)
                    {
                        LDobj.TechnologyId  = model.ldmlist[i].TechnologyId;
                        LDobj.LevelId       = model.ldmlist[i].LevelId;
                        LDobj.ScheduledDate = Convert.ToDateTime(model.ldmlist[i].Scheduledate);
                        LDobj.TrainingName  = model.ldmlist[i].Coursename;
                        LDobj.IsActive      = true;

                        LDobj.InstructorId = model.ldmlist[i].InstructorID;
                        db.Trainings.AddObject(LDobj);
                        db.SaveChanges();
                    }
                    TempData["Success"] = "Details Saved Successfully";
                }
                var LevelList                    = db.Master_TrainingLevel.ToList();
                var TechList                     = db.Master_TrainingTechnology.ToList();
                var InstructorList               = db.TrainingInstructors.ToList();
                List <LDCourseModel>  ldm        = new List <LDCourseModel>();
                LDCourseModel         lModel     = new LDCourseModel();
                List <SelectListItem> LevelList1 = new List <SelectListItem>();
                List <SelectListItem> TechList1  = new List <SelectListItem>();

                foreach (var list in LevelList)
                {
                    LevelList1.Add(new SelectListItem {
                        Text = list.LevelName, Value = Convert.ToString(list.LevelId)
                    });
                }
                lModel.LevelIDList = LevelList1;
                foreach (var list in TechList)
                {
                    TechList1.Add(new SelectListItem {
                        Text = list.TechnologyName, Value = Convert.ToString(list.TechnologyId)
                    });
                }
                lModel.TechIDList = TechList1;

                ViewBag.InstructorIDList = new SelectList(new[] { new TrainingInstructor()
                                                                  {
                                                                      InstructorId = 0, InstructorName = ""
                                                                  } }.Union(InstructorList), "InstructorId", "InstructorName", 0);

                for (int i = 0; i < 10; i++)
                {
                    LDCourseModel lm = new LDCourseModel();
                    lm.Coursename   = "";
                    lm.LevelId      = 0;
                    lm.TechnologyId = 0;
                    //ldm.LDM.
                    lm.InstructorID = 0;
                    lm.Scheduledate = null;
                    ldm.Add(lm);
                }
                ld.ldmlist = ldm;
                ld.LDM     = lModel;
            }
            catch (Exception Ex)
            {
                string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName);
            }
            return(RedirectToAction("AddCoursedetails", ld));
        }