public ActionResult Create(FormCollection form, Employee_beneficiary_profile model, string command) { try { ViewBag.Subscription_Syndicate = dbcontext.Subscription_Syndicate.Where(a => a.Type == Models.Infra.Type.Subscription).ToList().Select(m => new { Code = m.Subscription_Code + "-----[" + m.Subscription_Description + ']', ID = m.ID }); ViewBag.Employee_Profile = dbcontext.Employee_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.idemp = model.Employee_ProfileId; ViewBag.family = model.ID; if (ModelState.IsValid) { var Employee_ProfileId = int.Parse(model.Employee_ProfileId); var Employee_Profile = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == Employee_ProfileId); var Family_profile = form["Family_profile_No2"].Split(char.Parse(",")); var Family_name = form["Family_name"].Split(char.Parse(",")); var Percentage = form["Percentage"].Split(char.Parse(",")); var items = new List <Append_beneficiary_Family>(); for (var i = 0; i < Family_profile.Count(); i++) { if (Family_profile[i] != "" && Family_name[i] != "" && Percentage[i] != "") { items.Add(new Append_beneficiary_Family { Percentage = int.Parse(Percentage[i]), Family_name = Family_name[i], Family_profile = Family_profile[i] }); } } if (items.Count() > 0) { var add_items = dbcontext.Append_beneficiary_Family.AddRange(items); dbcontext.SaveChanges(); var benfit = new Employee_beneficiary_profile { Append_beneficiary_Family = add_items.ToList(), Code = model.Code, Employee_Profile = Employee_Profile, Legatee = model.Legatee, Employee_ProfileId = Employee_Profile.ID.ToString() }; dbcontext.Employee_beneficiary_profile.Add(benfit); dbcontext.SaveChanges(); } dbcontext.SaveChanges(); if (command == "Submit") { return(RedirectToAction("edit", "Employee_Profile", new { id = int.Parse(Employee_Profile.ID.ToString()) })); } return(RedirectToAction("Index", new { id = model.Employee_ProfileId })); } else { return(View(model)); } } catch (DbUpdateException e) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult Create(string id) { ViewBag.Subscription_Syndicate = dbcontext.Subscription_Syndicate.Where(a => a.Type == Models.Infra.Type.Subscription).ToList().Select(m => new { Code = m.Subscription_Code + "-----[" + m.Subscription_Description + ']', ID = m.ID }); // ViewBag.Employee_family_profile = dbcontext.Employee_family_profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.Employee_Profile = dbcontext.Employee_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.idemp = id; var stru = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Personnel); var model = dbcontext.Employee_beneficiary_profile.ToList(); var count = 0; if (model.Count() == 0) { count = 1; } else { var te = model.LastOrDefault().ID; count = te + 1; } //if (id != null) //{ // var ID = int.Parse(id); // var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == ID); // var x = emp.Employee_family_profile; // return View(x); //} // DateTime statis3 = Convert.ToDateTime("1/1/1900"); var ID = int.Parse(id); var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == ID); ViewBag.family = emp.Employee_family_profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); var EmployeeBeneficiary = new Employee_beneficiary_profile { Employee_ProfileId = emp.ID.ToString(), Code = stru.Structure_Code + count.ToString() }; return(View(EmployeeBeneficiary)); }