public ActionResult Create()
        {
            try
            {
                ViewBag.organ = dbcontext.Organization_Chart.ToList().Select(m => new { Code = m.Code + "-[" + m.unit_Description + ']', ID = m.ID });;
                ViewBag.setup = dbcontext.job_level_setup.ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });;
                ViewBag.sub   = dbcontext.Job_title_sub_class.ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });;


                ViewBag.cadre = new job_level_setup();
                var model = new man_power();
                model.from_year = 1900; model.to_year = 1901;
                var VM = new manpowerVM {
                    man_power = model, selected_organ = 0
                };
                return(View(VM));
            }
            catch (Exception e)
            {
                return(View());
            }
        }
 public ActionResult edit(string id)
 {
     try
     {
         ViewBag.organ = dbcontext.Organization_Chart.ToList().Select(m => new { Code = m.Code + "-[" + m.unit_Description + ']', ID = m.ID });;
         ViewBag.setup = dbcontext.job_level_setup.ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });;
         ViewBag.sub   = dbcontext.Job_title_sub_class.ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });;
         ViewBag.cadre = new job_level_setup();
         int ID    = int.Parse(id);
         var model = dbcontext.man_power.FirstOrDefault(m => m.ID == ID);
         var items = dbcontext.items_man_power.Where(m => m.man_power.ID == model.ID).ToList();
         model.items_man_power = items;
         var VM = new manpowerVM {
             man_power = model, selected_organ = model.Organization_ChartID
         };
         return(View(VM));
     }
     catch (Exception e)
     {
         return(View());
     }
 }
        public ActionResult Create(manpowerVM model, FormCollection Form)
        {
            try
            {
                ViewBag.organ = dbcontext.Organization_Chart.ToList().Select(m => new { Code = m.Code + "-[" + m.unit_Description + ']', ID = m.ID });;
                ViewBag.setup = dbcontext.job_level_setup.ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });;
                ViewBag.sub   = dbcontext.Job_title_sub_class.ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });;

                ViewBag.cadre = new job_level_setup();
                var check_date = dbcontext.man_power.FirstOrDefault(m => m.from_year == model.man_power.from_year);
                if (check_date != null)
                {
                    TempData["Message"] = HR.Resource.organ.thisyearhavealreadymanpoweryoucanaddyouritemsbyentertoeditactionandaddit;
                    return(RedirectToAction("index"));
                }
                else
                {
                    var manpoer = new man_power();
                    manpoer.Organization_ChartID = model.selected_organ;
                    manpoer.from_year            = model.man_power.from_year;
                    manpoer.to_year = model.man_power.to_year;


                    var job_id = Form["job_ID1"].Split(char.Parse(","));
                    //       var job_code = Form["job_code"].Split(char.Parse(","));

                    var level_id = Form["level_ID1"].Split(char.Parse(","));
                    //      var level_code = Form["level_code"].Split(char.Parse(","));

                    var sub_id = Form["sub_ID1"].Split(char.Parse(","));
                    //      var sub_code = Form["sub_code"].Split(char.Parse(","));

                    var count = Form["count"].Split(char.Parse(","));

                    var q1      = Form["q1"].Split(char.Parse(","));
                    var new_job = Form["new"].Split(char.Parse(","));
                    var q2      = Form["q2"].Split(char.Parse(","));
                    var q3      = Form["q3"].Split(char.Parse(","));
                    var q4      = Form["q4"].Split(char.Parse(","));
                    //    var id = Form["levelID"].Split(char.Parse(","));
                    var ss = new List <items_man_power>();

                    for (var i = 0; i < q1.Count(); i++)
                    {
                        if (q1[i] != "")
                        {
                            //          var IDlevel = int.Parse(id[i]);
                            //          var le = dbcontext.job_level_setup.FirstOrDefault(m => m.ID == IDlevel);

                            var item_de = new items_man_power
                            {
                                //                 cadre_code=le,
                                job_title_cardsID     = int.Parse(job_id[i]),
                                job_level_setupID     = int.Parse(level_id[i]),
                                Job_title_sub_classID = int.Parse(sub_id[i]),
                                current_jobs          = int.Parse(count[i]),
                                new_jobs = int.Parse(new_job[i]),
                                quarter1 = int.Parse(q1[i]),
                                quarter2 = int.Parse(q2[i]),
                                quarter3 = int.Parse(q3[i]),
                                quarter4 = int.Parse(q4[i]),
                            };

                            var item = dbcontext.items_man_power.Add(item_de);
                            dbcontext.SaveChanges();
                            ss.Add(item);
                        }
                    }
                    manpoer.items_man_power = ss;
                    dbcontext.man_power.Add(manpoer);
                    dbcontext.SaveChanges();
                    //=================================check for alert==================================
                    var get_result_check = HR.Controllers.check.check_alert("manpower plan card", 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)
            {
                TempData["Message"] = HR.Resource.organ.thiscodeIsalreadyexists;
                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }