public ActionResult EditAssign(salary_codeVM model, FormCollection form, string Command, string code, string name, string codetype, string codevaluetype) { try { ViewBag.checktype = dbcontext.Checktype.ToList().Select(m => new { Code = m.Code + "-[" + m.Description + ']', ID = m.ID }); ViewBag.extedned = dbcontext.ExtendedFields_Header.ToList().Select(m => new { Code = m.ExtendedFields_Code + "-[" + m.ExtendedFields_Desc + ']', ID = m.ID }); ViewBag.Subscription_Syndicate = dbcontext.Subscription_Syndicate.ToList().Select(m => new { Code = m.Subscription_Code + "-[" + m.Subscription_Description + ']', ID = m.ID }); ViewBag.debit = dbcontext.GL_AccountSetup.ToList().Select(m => new { Code = m.Account + "-[" + m.AccountName + ']', ID = m.ID }); ViewBag.credit = dbcontext.GL_AccountSetup.ToList().Select(m => new { Code = m.Account + "-[" + m.AccountName + ']', ID = m.ID }); ViewBag.code = code; ViewBag.name = name; ViewBag.codetype = codetype; ViewBag.codevaluetype = codevaluetype; var list = dbcontext.Employee_Financial_Contract_Header.Where(a => a.IsActive == true).ToList(); var lists = dbcontext.Employee_Financial_Contract_Header.ToList(); var De = dbcontext.Employee_Financial_Contract_Detail.Where(a => a.SalaryCodeID == code).ToList(); if (list != null) { for (int i = 0; i < De.Count(); i++) { var delete = dbcontext.Employee_Financial_Contract_Detail.Remove(De[i]); dbcontext.SaveChanges(); } for (int i = 0; i < list.Count(); i++) { Employee_Financial_Contract_Detail record = new Employee_Financial_Contract_Detail(); record.Contract_Number = list[i].ID.ToString(); record.SalaryCodeID = code; record.Salarycodedescription = name; record.SalaryCodeValue = 0; record.Type = codetype; record.ValueType = codevaluetype; dbcontext.Employee_Financial_Contract_Detail.Add(record); dbcontext.SaveChanges(); } } dbcontext.SaveChanges(); return(RedirectToAction("index")); } catch (Exception) { return(View(model)); } }
public ActionResult Create(Employee_Financial_Contract_Header model, string command, FormCollection form) { try { //var prof = int.Parse(model.Employee_Profile.ID); var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == model.Employee_Profile.ID); 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 EmpObj = dbcontext.Employee_Profile.FirstOrDefault(a => a.ID == model.Employee_Profile.ID); Employee_Financial_Contract_Header record = new Employee_Financial_Contract_Header(); var empid = EmpObj.Code + "------" + EmpObj.Name; record.Employee_Code = model.Employee_Code == null ? model.Employee_Code = EmpObj.ID.ToString() : model.Employee_Code; ViewBag.idemp = model.Employee_Code; record.Employee_Profile = EmpObj; if (ModelState.IsValid) { var list = dbcontext.Employee_Financial_Contract_Header.Where(a => a.Employee_Code == emp.ID.ToString()).ToList(); //var list = dbcontext.Employee_Financial_Contract_Header.ToList(); if (list.Count() == 0) { record.IsActive = true; } else { var te = list.Where(m => m.IsActive == true); foreach (var item in te) { item.IsActive = false; } record.IsActive = true; } dbcontext.SaveChanges(); record.Contract_Number = model.Contract_Number; record.From_Date = model.From_Date; record.To_Date = model.To_Date; if (model.From_Date > model.To_Date) { TempData["Message"] = HR.Resource.Personnel.FromdatebiggerTodate; return(View(model)); } var Header = dbcontext.Employee_Financial_Contract_Header.Add(record); 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 = Header.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 = model.Employee_Code })); } else { return(View(model)); } } catch (DbUpdateException e) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }