public ActionResult Edit(int id)
        {
            try
            {
                ViewBag.Employee_Profile = dbcontext.Employee_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.salaryitem       = dbcontext.salary_code.Where(a => a.SourceEntry == 1).ToList().Select(m => new { Code = m.SalaryCodeID + "-[" + m.SalaryCodeDesc + ']', ID = m.ID });

                var old_model = dbcontext.Employee_Financial_Contract_Header.FirstOrDefault(m => m.ID == id);
                var emp       = old_model.Employee_Profile;

                var headera = new VMFin {
                    Employee_Financial_Contract_Header = old_model
                };

                ViewBag.idemp = old_model.Employee_Profile.ID.ToString();
                var old_details = dbcontext.Employee_Financial_Contract_Detail.Where(m => m.Contract_Number == old_model.ID.ToString()).ToList();
                var new_model   = new VMFin {
                    Employee_Financial_Contract_Detail = old_details, Employee_Financial_Contract_Header = old_model
                };
                return(View(new_model));
            }
            catch (Exception e)
            { return(View()); }
        }
        public ActionResult Edit(VMFin model, string command, FormCollection form)
        {
            try
            {
                ViewBag.Employee_Profile = dbcontext.Employee_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID });
                ViewBag.salaryitem       = dbcontext.salary_code.Where(a => a.SourceEntry == 1).ToList().Select(m => new { Code = m.SalaryCodeID + "-[" + m.SalaryCodeDesc + ']', ID = m.ID });
                //   var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == prof);
                var record = dbcontext.Employee_Financial_Contract_Header.FirstOrDefault(m => m.ID == model.Employee_Financial_Contract_Header.ID);
                var emp    = record.Employee_Profile;
                ViewBag.idemp = model.Employee_Financial_Contract_Header.Contract_Number;

                var list = dbcontext.Employee_Financial_Contract_Header.Where(a => a.IsActive == true).ToList();

                if (list != null)
                {
                    for (int i = 0; i < list.Count(); i++)
                    {
                        list[i].IsActive = false;
                    }
                    record.IsActive = true;
                }
                dbcontext.SaveChanges();
                record.Contract_Number = model.Employee_Financial_Contract_Header.Contract_Number;
                record.From_Date       = model.Employee_Financial_Contract_Header.From_Date;
                record.To_Date         = model.Employee_Financial_Contract_Header.To_Date;
                //if (model.Employee_Financial_Contract_Header.From_Date > model.Employee_Financial_Contract_Header.To_Date)
                //{
                //    TempData["Message"] = HR.Resource.Personnel.FromdatebiggerTodate;
                //    return View(model);
                //}
                dbcontext.SaveChanges();
                ///////////////////////////////////////////
                ///
                var update_details = dbcontext.Employee_Financial_Contract_Detail.Where(m => m.Contract_Number == record.ID.ToString()).ToList();
                dbcontext.Employee_Financial_Contract_Detail.RemoveRange(update_details);
                dbcontext.SaveChanges();

                var codeid       = form["codeid"].Split(',');
                var SalaryDes    = form["SalaryDes"].Split(',');
                var TypeE        = form["TypeE"].Split(',');
                var ValueType    = form["ValueType"].Split(',');
                var DefaultValue = form["DefaultValue"].Split(',');
                var Extendedco   = form["Extendedco"].Split(',');
                var Extendedna   = form["Extendedna"].Split(',');

                for (var i = 0; i < codeid.Length; i++)
                {
                    if (codeid[i] != "")
                    {
                        var new_details = new Employee_Financial_Contract_Detail {
                            Contract_Number = record.ID.ToString(), Created_By = User.Identity.Name, Created_Date = DateTime.Now.Date, SalaryCodeID = codeid[i], SalaryCodeValue = double.Parse(DefaultValue[i]), Salarycodedescription = SalaryDes[i], Type = TypeE[i], ValueType = ValueType[i]                                                       /*, ExtendedFields_Code = Extendedco[i], ExtendedFields_Desc = Extendedna[i]*/
                        };
                        dbcontext.Employee_Financial_Contract_Detail.Add(new_details);
                        dbcontext.SaveChanges();
                    }
                }

                if (command == "Submit")
                {
                    return(RedirectToAction("edit", "Employee_Profile", new { id = int.Parse(record.Employee_Code) }));
                }
                return(RedirectToAction("Index", new { id = record.Employee_Code }));
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(View(model));
            }
            catch (Exception e)
            { return(View(model)); }
        }