Beispiel #1
0
        public ActionResult create(int?ID_course)
        {
            try
            {
                ViewBag.centers = dbcontext.TrainingCenter.ToList().Select(m => new { Code = m.TrainingCenters_Code + "-[" + m.TrainingCenters_Desc + ']', ID = m.ID });
                ViewBag.course  = dbcontext.Cours.ToList().Select(m => new { Code = m.Course_Code + "-[" + m.Course_Desc + ']', ID = m.ID });

                var new_model = new Course_Centers();
                if (ID_course != null)
                {
                    var cou_q = dbcontext.Course_Centers.Where(m => m.Course_Code == ID_course.ToString()).ToList();
                    if (cou_q.Count() > 0)
                    {
                        return(RedirectToAction("edit", new { id = ID_course }));
                    }
                    var course = dbcontext.Cours.FirstOrDefault(m => m.ID == ID_course);
                    new_model.Course_Code = course.ID.ToString();
                }
                /////

                return(View(new_model));
            }
            catch (Exception)
            {
                return(RedirectToAction("index"));
            }
        }
Beispiel #2
0
        public ActionResult create(FormCollection form, Course_Centers model)
        {
            try
            {
                ViewBag.centers = dbcontext.TrainingCenter.ToList().Select(m => new { Code = m.TrainingCenters_Code + "-[" + m.TrainingCenters_Desc + ']', ID = m.ID });
                ViewBag.course  = dbcontext.Cours.ToList().Select(m => new { Code = m.Course_Code + "-[" + m.Course_Desc + ']', ID = m.ID });

                //================================
                var center_D = form["center_id"].Split(',');
                for (var i = 0; i < center_D.Length; i++)
                {
                    if (center_D[i] != "")
                    {
                        var ID         = int.Parse(center_D[i]);
                        var CENTER     = dbcontext.TrainingCenter.FirstOrDefault(m => m.ID == ID);
                        var Cource_cen = new Course_Centers {
                            Course_Code = model.Course_Code, center_des = CENTER.TrainingCenters_Code + "-" + CENTER.TrainingCenters_Desc, TrainingCenters_Code = CENTER.ID.ToString(), Created_By = User.Identity.Name, Created_Date = DateTime.Now.Date
                        };
                        dbcontext.Course_Centers.Add(Cource_cen);
                        dbcontext.SaveChanges();
                    }
                }
                //================================
                //=================================check for alert==================================

                var get_result_check = HR.Controllers.check.check_alert("course training centers carde", HR.Models.user.Action.Create, HR.Models.user.type_field.form);
                if (get_result_check != null)
                {
                    var inbox = new Models.user.Alert_inbox {
                        send_from_user_id = User.Identity.Name, send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message
                    };
                    if (get_result_check.until != null)
                    {
                        if (get_result_check.until.Value.Year != 0001)
                        {
                            inbox.until = get_result_check.until;
                        }
                    }
                    ApplicationDbContext dbcontext = new ApplicationDbContext();
                    dbcontext.Alert_inbox.Add(inbox);
                    dbcontext.SaveChanges();
                }
                //===================================================================================
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(View());
            }
            catch (Exception e)
            {
                return(View());
            }
        }
Beispiel #3
0
        public ActionResult edit(int id)
        {
            try
            {
                ViewBag.centers = dbcontext.TrainingCenter.ToList().Select(m => new { Code = m.TrainingCenters_Code + "-[" + m.TrainingCenters_Desc + ']', ID = m.ID });
                ViewBag.course  = dbcontext.Cours.ToList().Select(m => new { Code = m.Course_Code + "-[" + m.Course_Desc + ']', ID = m.ID });

                var cours      = dbcontext.Cours.FirstOrDefault(m => m.ID == id);
                var edit_model = new Course_Centers {
                    Course_Code = cours.ID.ToString()
                };
                ViewBag.course_code5 = cours.ID.ToString();
                return(View(edit_model));
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(RedirectToAction("index"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("index"));
            }
        }