public ActionResult Create(string SelectedSkillSetCSV, string MandatorySkillSetCSV, [Bind(Include = "RequirementId,JobNumber,JobTitle,Priority,Description,Location,Duration,HourlyBuyRate,HourlyBillingRate,JobTypeId,OneTimeFee,Status,RecruiterId,Tier1ClientId,Tier2ClientId,AccountManagerId,NoofPositions")] Requirement requirement) { try { if (ModelState.IsValid) { if (requirement.NoofPositions == 1) { requirement.CreatedBy = User.Identity.GetUserId(); requirement.CreatedTimestamp = DateTime.Now; AddSkillSet(SelectedSkillSetCSV, MandatorySkillSetCSV, requirement); db.Requirements.Add(requirement); db.SaveChanges(); } else { for (int i = 1; i <= requirement.NoofPositions; i++) { if (requirement.RequirementId != 0) { var duprequirement = requirement.Copy(); duprequirement.CreatedBy = User.Identity.GetUserId(); duprequirement.CreatedTimestamp = DateTime.Now; AddSkillSet(SelectedSkillSetCSV, MandatorySkillSetCSV, duprequirement); db.Requirements.Add(duprequirement); } else { requirement.CreatedBy = User.Identity.GetUserId(); requirement.CreatedTimestamp = DateTime.Now; AddSkillSet(SelectedSkillSetCSV, MandatorySkillSetCSV, requirement); db.Requirements.Add(requirement); } db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.Tier1Clients = new SelectList(db.Clients, "ClientId", "Name"); ViewBag.Tier2Clients = new SelectList(db.Clients, "ClientId", "Name"); var recruiters = db.Recruiters.Include(u => u.AspNetUser).ToList().Select(r => new { RecruiterId = r.RecruiterId, RecruiterName = r.AspNetUser.FirstName + " " + r.AspNetUser.LastName }); ViewBag.Recruiters = new SelectList(recruiters, "RecruiterId", "RecruiterName"); ViewBag.AccountManagers = new SelectList(recruiters, "RecruiterId", "RecruiterName"); ViewBag.Priorities = new Utility().Priority; ViewBag.RequirementStatus = new Utility().RequirementStatus; ViewBag.JobType = new Utility().JobType; return(View(requirement)); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); Logger.LogMessage(exceptionMessage); return(RedirectToAction("AppError", "Error")); } catch (Exception exp) { Logger.LogException(exp); return(RedirectToAction("AppError", "Error")); } }