public ActionResult Create(string id) { ViewBag.Employee_Profile = dbcontext.Applicant_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.Contactmethods = dbcontext.Contact_methods.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.Recuirtment); var model = dbcontext.Applicant_Contact_Profile.ToList(); var count = 0; if (model.Count() == 0) { count = 1; } else { var te = model.LastOrDefault().ID; count = te + 1; } var ID = int.Parse(id); var emp = dbcontext.Applicant_Profile.FirstOrDefault(m => m.ID == ID); var EmployeeContact = new Applicant_Contact_Profile { Applicant_Profile = emp, Employee_ProfileId = emp.ID.ToString(), Code = stru.Structure_Code + count.ToString() }; return(View(EmployeeContact)); }
public ActionResult Create(Applicant_Contact_Profile model, string command) { try { ViewBag.Employee_Profile = dbcontext.Applicant_Profile.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.Contactmethods = dbcontext.Contact_methods.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); //if (ModelState.IsValid) //{ var emp = int.Parse(model.Employee_ProfileId); var EmpObj = dbcontext.Applicant_Profile.FirstOrDefault(a => a.ID == emp); //var record = dbcontext.Employee_contact_profile.FirstOrDefault(m => m.ID == emp.Employee_contact_profile); Applicant_Contact_Profile record = new Applicant_Contact_Profile(); var empid = EmpObj.Code + "------" + EmpObj.Name; record.Employee_ProfileId = model.Employee_ProfileId == null ? model.Employee_ProfileId = EmpObj.ID.ToString() : model.Employee_ProfileId; ViewBag.idemp = model.Employee_ProfileId; record.Applicant_Profile = EmpObj; record.Code = model.Code; record.Contact_method_detail = model.Contact_method_detail; record.Primary = model.Primary; record.Employee_ProfileId = model.Employee_ProfileId; record.Comments = model.Comments; record.ContactmethodsId = model.ContactmethodsId; dbcontext.Applicant_Contact_Profile.Add(record); dbcontext.SaveChanges(); if (command == "Submit") { return(RedirectToAction("edit", "Applicant_Profile", new { id = EmpObj.ID })); } return(RedirectToAction("Index", new { id = EmpObj.ID })); //} //else //{ return(View(model)); //} } catch (DbUpdateException e) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }