public int AddEditActivity(AngularActivity selectedActivity) { int newId = 0; string success = "ono"; try { using (var db = new curtisGodaddyEntities()) { JobSearchActivity dbJobSearchActivity = null; if (selectedActivity.ActivityId == 0) { dbJobSearchActivity = new JobSearchActivity { }; dbJobSearchActivity.JobListingId = selectedActivity.JobListingId; db.JobSearchActivities.Add(dbJobSearchActivity); } else { dbJobSearchActivity = db.JobSearchActivities.Where(j => j.JobSearchActivityId == selectedActivity.ActivityId).First(); } dbJobSearchActivity.Comments = selectedActivity.Comments; dbJobSearchActivity.ActivityDate = DateTime.Parse(selectedActivity.ActivityDate); dbJobSearchActivity.ActivityStatus = selectedActivity.ActivityStatus; db.SaveChanges(); newId = dbJobSearchActivity.JobSearchActivityId; success = "ok"; } } catch (DbEntityValidationException ex) { success = "ValidationExceptions: "; foreach (var eve in ex.EntityValidationErrors) { success += eve.Entry.Entity.GetType().Name + ": " + eve.Entry.State; foreach (var ve in eve.ValidationErrors) { success += " Property: " + ve.PropertyName + " Error: " + ve.ErrorMessage; } } } catch (Exception ex) { success = ex.Message; if (ex.InnerException != null) success += " inner: " + ex.InnerException.Message; } return newId; }
public int AddEditJobListing(AngularJobListing selectedJobListing) { string success = "ono"; int newId = 0; try { using (var db = new curtisGodaddyEntities()) { JobListing dbJobListing = null; if (selectedJobListing.Id == 0) { dbJobListing = new JobListing { }; dbJobListing.JobSearchId = db.GetaJob_User.Where(u => u.UserName == User.Identity.Name).First().CurrentJobSearchId; db.JobListings.Add(dbJobListing); } else { dbJobListing = db.JobListings.Where(j => j.JobListingId == selectedJobListing.Id).First(); } dbJobListing.JobTitle = selectedJobListing.JobTitle; dbJobListing.PostedDate = DateTime.Parse(selectedJobListing.PostedDate); dbJobListing.Rate = selectedJobListing.Rate; dbJobListing.Comments = selectedJobListing.Comments; dbJobListing.Distance = selectedJobListing.Distance; dbJobListing.EmploymentType = selectedJobListing.EmploymentType; dbJobListing.ListingStatus = selectedJobListing.ListingStatus; dbJobListing.ListingSource = selectedJobListing.ListingSource; dbJobListing.Desirability = selectedJobListing.Desirability; dbJobListing.Fit = selectedJobListing.Fit; dbJobListing.TargetCompanyId = AddEditTargetCompany(selectedJobListing); int? agencyId = AddEditAgency(selectedJobListing); if (agencyId != null) selectedJobListing.AgencyId = agencyId.Value; dbJobListing.AgentId = AddEditAgent(selectedJobListing); db.SaveChanges(); newId = dbJobListing.JobListingId; } } catch (DbEntityValidationException ex) { success = "ValidationExceptions: "; foreach (var eve in ex.EntityValidationErrors) { success += eve.Entry.Entity.GetType().Name + ": " + eve.Entry.State; foreach (var ve in eve.ValidationErrors) { success += " Property: " + ve.PropertyName + " Error: " + ve.ErrorMessage; } throw new Exception(success); } } catch (Exception ex) { success = ex.Message; if (ex.InnerException != null) success += " inner: " + ex.InnerException.Message; throw new Exception(success); } return newId; }
int? AddEditTargetCompany(AngularJobListing selectedJobListing) { //Unable to update the EntitySet 'TargetCompany' because it has a DefiningQuery and no<InsertFunction> //element exists in the<ModificationFunctionMapping> element to support the current operation. int? targetCompanyId = null; TargetCompany targetCompany = null; if (!string.IsNullOrWhiteSpace(selectedJobListing.TargetCompanyName)) using (var db = new curtisGodaddyEntities()) { if ((selectedJobListing.Id != 0) && selectedJobListing.TargetCompanyId != 0) targetCompany = db.TargetCompanies.Where(tc => tc.CompanyId == selectedJobListing.TargetCompanyId).FirstOrDefault(); if (targetCompany == null) targetCompany = db.TargetCompanies.Where(tc => tc.Name == selectedJobListing.TargetCompanyName).FirstOrDefault(); if (targetCompany == null) { targetCompany = new TargetCompany(); db.TargetCompanies.Add(targetCompany); } targetCompany.Name = selectedJobListing.TargetCompanyName; targetCompany.StreetAddress = selectedJobListing.TargetCompanyStreetAddress; targetCompany.City = selectedJobListing.TargetCompanyCity; targetCompany.State = selectedJobListing.TargetCompanyState; targetCompany.Zip = selectedJobListing.TargetCompanyZip; db.SaveChanges(); targetCompanyId = db.TargetCompanies.Where(c => c.Name == selectedJobListing.TargetCompanyName).First().CompanyId; } return targetCompanyId; }
int? AddEditAgent(AngularJobListing selectedJobListing) { int? agentId = null; using (var db = new curtisGodaddyEntities()) { Agent agent = null; if (selectedJobListing.AgentId != 0) { agent = db.Agents.Where(a => a.AgentId == selectedJobListing.AgentId).FirstOrDefault(); } if (agent == null) { if (!string.IsNullOrWhiteSpace(selectedJobListing.AgentName)) agent = db.Agents.Where(a => a.AgentName == selectedJobListing.AgentName).FirstOrDefault(); } if (agent == null) { agent = new Agent(); db.Agents.Add(agent); } agent.AgentName = selectedJobListing.AgentName; agent.WorkPhone = selectedJobListing.AgentWorkPhone; agent.CellPhone = selectedJobListing.AgentCellPhone; agent.Email = selectedJobListing.AgentEmail; agent.AgencyId = selectedJobListing.AgencyId; db.SaveChanges(); agentId = agent.AgentId; } return agentId; }
int? AddEditAgency(AngularJobListing selectedJobListing) { int? agencyId = null; if (!string.IsNullOrWhiteSpace(selectedJobListing.AgencyName)) { using (var db = new curtisGodaddyEntities()) { Agency agency = null; if ((selectedJobListing.Id != 0) && selectedJobListing.AgencyId != 0) { agency = db.Agencies.Where(a => a.AgencyId == selectedJobListing.AgencyId).FirstOrDefault(); } if (agency == null) agency = db.Agencies.Where(a => a.Name == selectedJobListing.AgencyName).FirstOrDefault(); if (agency == null) { agency = new Agency(); db.Agencies.Add(agency); } agency.Name = selectedJobListing.AgencyName; agency.StreetAddress = selectedJobListing.AgencyStreetAddress; agency.City = selectedJobListing.AgencyCity; agency.State = selectedJobListing.AgencyState; agency.Zip = selectedJobListing.AgencyZip; agency.WorkPhone = selectedJobListing.AgencyWorkPhone; agency.CellPhone = selectedJobListing.AgencyCellPhone; agency.Email = selectedJobListing.AgencyEmail; db.SaveChanges(); agencyId = db.Agencies.Where(c => c.Name == selectedJobListing.AgencyName).First().AgencyId; } } return agencyId; }
public string AddEditRef(AngularRef selectedRef) { using (var db = new curtisGodaddyEntities()) { if (selectedRef.RefCode == -1) { var dbRef = new DropDownValue() { RefDescription = selectedRef.RefDescription, RefType = selectedRef.RefType }; db.DropDownValues.Add(dbRef); db.SaveChanges(); } else { var dbRef = db.DropDownValues.Where(r => r.RefCode == selectedRef.RefCode).First(); dbRef.RefDescription = selectedRef.RefDescription; db.SaveChanges(); } } return "ok"; }
public string AddEditJobSearch(AngularJobSearchs selectedJobSearch) { string success = "ono"; try { using (var db = new curtisGodaddyEntities()) { JobSearch jobSearch = null; if (selectedJobSearch.id == 0) { jobSearch = new JobSearch(); jobSearch.UserId = db.GetaJob_User.Where(p => p.UserName == User.Identity.Name).FirstOrDefault().UserId; db.JobSearches.Add(jobSearch); } else { jobSearch = db.JobSearches.Where(j => j.JobSearchId == selectedJobSearch.id).First(); } jobSearch.Description = selectedJobSearch.description; jobSearch.Start = DateTime.Parse(selectedJobSearch.start); if (selectedJobSearch.completed == null) jobSearch.Completed = null; else jobSearch.Completed = DateTime.Parse(selectedJobSearch.completed); db.SaveChanges(); success = "ok"; } } catch (DbEntityValidationException ex) { success = "ValidationExceptions: "; foreach (var eve in ex.EntityValidationErrors) { success += eve.Entry.Entity.GetType().Name + ": " + eve.Entry.State; foreach (var ve in eve.ValidationErrors) { success += " Property: " + ve.PropertyName + " Error: " + ve.ErrorMessage; } } } catch (Exception ex) { success = ex.Message; if (ex.InnerException != null) success += " inner: " + ex.InnerException.Message; } return success; }