public ActionResult Create()
        {
            try
            {
                var record = new Discipline_PunishmentTransaction();
                ViewBag.employee   = dbcontext.Employee_Profile.Where(m => m.Active == true).ToList().Select(m => new { Code = "" + m.Code + "--[" + m.Full_Name + ']', ID = m.ID }).ToList();
                ViewBag.restoption = dbcontext.Discipline_PunishmentRestOption.ToList().Select(m => new { Code = "" + m.RestOption_Code + "--[" + m.RestOption_Desc + ']', ID = m.ID }).ToList();
                ViewBag.punishment = dbcontext.Discipline_Punishment.ToList().Select(m => new { Code = "" + m.Punishment_Code + "--[" + m.Punishment_Desc + ']', ID = m.ID }).ToList();
                try
                {
                    var stru  = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Personnel).Structure_Code;
                    var model = dbcontext.Discipline_PunishmentTransaction.ToList();
                    if (model.Count() == 0)
                    {
                        record.Transaction_Number = stru + "1";
                    }
                    else
                    {
                        record.Transaction_Number = stru + (model.LastOrDefault().ID + 1).ToString();
                    }
                    record.Transaction_Date = DateTime.Now.Date;
                    record.Event_Date       = DateTime.Now.Date;
                    record.RestOption_Date  = DateTime.Now.Date;
                    record.Custom_Rest      = false;

                    return(View(record));
                }
                catch (Exception e)
                {
                    return(RedirectToAction("index"));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("index"));
            }
        }
        public ActionResult Create(Discipline_PunishmentTransaction model, FormCollection form)
        {
            try
            {
                var record = new Discipline_PunishmentTransaction();
                ViewBag.employee = dbcontext.Employee_Profile.Where(m => m.Active == true).ToList().Select(m => new { Code = "" + m.Code + "--[" + m.Full_Name + ']', ID = m.ID }).ToList();

                ViewBag.restoption = dbcontext.Discipline_PunishmentRestOption.ToList().Select(m => new { Code = "" + m.RestOption_Code + "--[" + m.RestOption_Desc + ']', ID = m.ID }).ToList();
                ViewBag.punishment = dbcontext.Discipline_Punishment.ToList().Select(m => new { Code = "" + m.Punishment_Code + "--[" + m.Punishment_Desc + ']', ID = m.ID }).ToList();
                //=======================================================================================
                var St_ = new status {
                    created_by = User.Identity.Name, created_bydate = DateTime.Now.Date, statu = check_status.created
                };
                var status = dbcontext.status.Add(St_);
                dbcontext.SaveChanges();
                //=============================================Header====================================
                var a1 = form["RestOption_Code"].Split(',');
                if (a1.Length == 1)
                {
                    model.RestOption_Code = null;
                    model.Custom_Rest     = false;
                }
                else
                {
                    model.Custom_Rest = true;
                    if (a1[1] == "")
                    {
                        return(View(model));
                    }
                    else
                    {
                        model.RestOption_Code = a1[1];
                    }
                }

                model.stat_ID           = status.ID;
                model.stat              = status;
                model.Created_By        = User.Identity.Name;
                model.Created_Date      = DateTime.Now.Date;
                model.Posted_to_payroll = false;
                if (int.Parse(model.Employee_Code) > 0)
                {
                    var ID_emp = int.Parse(model.Employee_Code);
                    var emp    = dbcontext.Employee_Profile.FirstOrDefault(m => m.Active == true && m.ID == ID_emp);
                    model.em = emp.Code + "-" + emp.Full_Name;
                }
                var header = dbcontext.Discipline_PunishmentTransaction.Add(model);

                dbcontext.SaveChanges();
                //=================================================Details=============================

                var punishent_group = form["center_id"].Split(',');
                var Frequency       = form["frequency_"].Split(',');
                var penalit         = form["Penality_"].Split(',');
                var rest_date       = form["rest_D"].Split(',');
                var extra           = form["extra"].Split(',');
                var G = form["G"].Split(',');
                for (var i = 0; i < punishent_group.Length; i++)
                {
                    if (punishent_group[i] != "")
                    {
                        var Pun_id        = int.Parse(punishent_group[i]);
                        var puni          = dbcontext.Discipline_Punishment.FirstOrDefault(m => m.ID == Pun_id);
                        var Pen_id        = int.Parse(penalit[i]);
                        var pen           = dbcontext.Discipline_PenaltyItem_Header.FirstOrDefault(m => m.ID == Pen_id);
                        var model_details = new Discipline_PunishmentTransaction_Detail {
                            extra_frecuany = int.Parse(extra[i]), guide = Guid.Parse(G[i]), Punishment_Code = puni.ID.ToString(), punis_des = puni.Punishment_Code + '-' + puni.Punishment_Desc, PenaltyItem_Code = pen.ID.ToString(), penal_des = pen.PenaltyItem_Code + '-' + pen.PenaltyItem_Desc, Punishment_Frequency = (short)int.Parse(Frequency[i]), Punishment_RestDate = Convert.ToDateTime(rest_date[i]), Transaction_Number = header.Transaction_Number, Created_By = User.Identity.Name, Created_Date = DateTime.Now.Date
                        };
                        dbcontext.Discipline_PunishmentTransaction_Detail.Add(model_details);
                        dbcontext.SaveChanges();
                    }
                }
                //=================================check for alert==================================
                var get_result_check = HR.Controllers.check.check_alert("punishment transaction", HR.Models.user.Action.Create, 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;
                        }
                    }
                    dbcontext.Alert_inbox.Add(inbox);
                    dbcontext.SaveChanges();
                }
                //==================================================================================
                //===================================================
                return(RedirectToAction("index"));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }