public void Delete(int id) { db.Entry(new OnlineJobSite { OnlineJobSiteId = id }).State = EntityState.Deleted; db.SaveChanges(); }
public void Delete(int id) { db.Entry(new JobApplicant { JobApplicantId = id }).State = EntityState.Deleted; db.SaveChanges(); }
public virtual void Update([NotNull] TEntity entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(Update)} entity must not be null"); } dbSet.Attach(entity); context.Entry(entity).State = EntityState.Modified; }
public async Task <int> AddJobAsync(Job2Dto job2Dto) { _logger.LogInformation("Incoming Dto {0}", job2Dto); string currentUsername = GetCurrentUserEmail(); var job = _mapper.Map <Job>(job2Dto.Job); if (job != null) { JobCreatedIntegrationEvent jobCreatedEvent = null; await ResilientTransaction.New(_dbContext).ExecuteAsync(async() => { job.TransfereeId = SaveTransferee(job2Dto.Transferee); job.AccountEntity = _dbContext.AccountEntity.FirstOrDefault(a => a.Id == job.AccountEntityId); var dateTimeAdded = DateTime.UtcNow; job.DateCreated = dateTimeAdded; job.DateModified = dateTimeAdded; job.CreatedBy = GetCurrentUserEmail(); job.ModifiedBy = GetCurrentUserEmail(); if (job2Dto.Job.IsSurveyAndBid) { job.JobStatus = JobStatusIdentifier.SURVEY_BID; } _dbContext.Job.Attach(job); _dbContext.Entry(job).State = EntityState.Added; await _dbContext.SaveChangesAsync(); //update the fks in the job table var kvp = await SaveAddresses(job2Dto.JobInfo); job.OriginAddressId = kvp.FirstOrDefault(s => s.Key == AddressType.ORIGIN).Value; job.DestinationAddressId = kvp.FirstOrDefault(s => s.Key == AddressType.DESTINATION).Value; await _dbContext.SaveChangesAsync(); jobCreatedEvent = job.FromJob <JobCreatedIntegrationEvent>(); jobCreatedEvent.Transferee = job2Dto.ToTransfereeIntegrationEvent <TransfereeCreatedIntegrationEvent>(); jobCreatedEvent.UserId = GetJobsMoveConsultantEmail(job.Id); await _eventLogService.SaveEventAsync(jobCreatedEvent); }); // Publish the integration event through the event bus _eventBus.Publish(jobCreatedEvent); await _eventLogService.MarkEventAsPublishedAsync(jobCreatedEvent.Id); _logger.LogInformation("Job added {0}", job.Id); } return(job.Id); }
public IHttpActionResult PutRegisterApplicant(int id, RegisterApplicant registerApplicant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != registerApplicant.RegisterApplicantId) { return(BadRequest()); } db.Entry(registerApplicant).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RegisterApplicantExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutJob([FromRoute] int id, [FromBody] Job job) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != job.Id) { return(BadRequest()); } _context.Entry(job).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> Edit([Bind(Include = "Id,AgentId,JobNumber,Title,StartTime,EndTime,Status,CustomerName,CustomerAddress,CustomerPhoneNumber,WorkPerformed,CreatedAt,UpdatedAt,Version,Deleted")] Job job) { if (ModelState.IsValid) { db.Entry(job).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(job)); }
public ActionResult Edit([Bind(Include = "Id,Title,Description,ValidDate,Location,Count,Wage,CompanyId")] Job job) { if (ModelState.IsValid) { ctx.Entry(job).State = EntityState.Modified; ctx.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(ctx.Companies, "Id", "Name", job.CompanyId); return(View(job)); }
public ActionResult ModificarJob(int id, Job job) { if (id != job.Id) { return(BadRequest()); } _context.Entry(job).State = EntityState.Modified; _context.SaveChanges(); return(NoContent()); }
public ActionResult Edit(Company company) { if (ModelState.IsValid) { db.Entry(company).State = EntityState.Modified; //Company db_company = db.Companies.Find(company.Id); //db_company.Name = company.Name; //db_company.CellPhone = company.CellPhone; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(company)); }
public bool Update(OnlineJobSite oj, bool childIncluded = false) { // db.Entry(trade).State = EntityState.Modified; var orignal = db.OnlineJobSites.Include(x => x.JobAdvertisements).First(x => x.OnlineJobSiteId == oj.OnlineJobSiteId); orignal.OnlineJobSiteName = oj.OnlineJobSiteName; orignal.StartedJourney = oj.StartedJourney; orignal.Web = oj.Web; if (oj.JobAdvertisements != null && oj.JobAdvertisements.Count > 0) { var courses = oj.JobAdvertisements.ToArray(); for (var i = 0; i < courses.Length; i++) { var temp = orignal.JobAdvertisements.FirstOrDefault(c => c.JobAdvertisementId == courses[i].JobAdvertisementId); if (temp != null) { temp.JobTypeName = courses[i].JobTypeName; temp.Responsibility = courses[i].Responsibility; } else { orignal.JobAdvertisements.Add(courses[i]); } } foreach (var c in orignal.JobAdvertisements) { var temp = oj.JobAdvertisements.FirstOrDefault(t => t.JobAdvertisementId == c.JobAdvertisementId); if (temp == null) { db.Entry(c).State = EntityState.Deleted; } } } return(db.SaveChanges() > 0); }
public async Task <IActionResult> ChangePassword(UserViewModel model) { var user = await _dbContext.User.FindAsync(GetCurrentUserId()); if (user == null) { return(Ok("用户不存在".Error())); } if (model.Password.NullOrEmpty()) { return(Ok("密码不能为空".Error())); } if (user.HashPassword != model.Password.MD5Encrypt()) { return(Ok("密码不正确".Error())); } var newHashPassword = model.NewPassword.MD5Encrypt(); if (user.HashPassword == newHashPassword) { return(Ok("新密码不能与旧密码一致".Error())); } user.HashPassword = newHashPassword; _dbContext.Entry(user).Property(nameof(DashboardUser.HashPassword)).IsModified = true; await _dbContext.SaveChangesAsync(); // await _dbContext.Database.ExecuteSqlInterpolatedAsync($@"Update {nameof(DashboardUser)} //set {nameof(DashboardUser.HashPassword)}={newHashPassword} Where Id={user.Id}"); return(Ok(EmptyJson.Success())); }
public void UpdateVacancy(Vacancy vacancy) { context.Entry(vacancy).State = EntityState.Modified; }
static void Sync() { SalesforceClient client = new SalesforceClient(true); Task <IEnumerable <Case> > task = client.GetActiveCases(null); task.Wait(); IEnumerable <Case> cases = task.Result; JobDbContext db = new JobDbContext(); var caseNumbers = new List <string>(); foreach (Case c in cases) { string customer = c.Contact.Name; string caseNumber = c.CaseNumber.Substring(4); string title = c.Subject; string status = SalesforceClient.MapStatus(c.Status); caseNumbers.Add(caseNumber); Job job = db.JobsDbSet.Where(j => j.JobNumber == caseNumber).FirstOrDefault(); if (job == null) { db.JobsDbSet.Add( new Job() { Id = Guid.NewGuid().ToString(), JobNumber = caseNumber, AgentId = "2", CustomerName = customer, CustomerAddress = "One Microsoft Way, Redmond", CustomerPhoneNumber = "1-206-888-8888", Status = status, Title = title, StartTime = "13:00", EndTime = "14:00" }); } else { job.Title = title; job.Status = status; job.CustomerName = customer; } } db.SaveChanges(); // handle deletions foreach (Job job in db.JobsDbSet) { if (caseNumbers.Contains(job.JobNumber) == false) { db.Entry(job).Entity.Deleted = true; } } db.SaveChanges(); Console.WriteLine("WebJob ran at: " + DateTime.Now.ToString()); }
public IHttpActionResult PutOnlineJobSite(int id, OnlineJobSite onlineJobSite) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != onlineJobSite.OnlineJobSiteId) { return(BadRequest()); } var ext = db.OnlineJobSites.Include(x => x.JobAdvertisements).Include(y => y.RegisterApplicants).First(x => x.OnlineJobSiteId == onlineJobSite.OnlineJobSiteId); ext.OnlineJobSiteName = onlineJobSite.OnlineJobSiteName; ext.StartedJourney = onlineJobSite.StartedJourney; ext.Web = onlineJobSite.Web; ext.Response = onlineJobSite.Response; if (onlineJobSite.JobAdvertisements != null && onlineJobSite.JobAdvertisements.Count > 0) { var prs = onlineJobSite.JobAdvertisements.ToArray(); for (var i = 0; i < prs.Length; i++) { var temp = ext.JobAdvertisements.FirstOrDefault(c => c.JobAdvertisementId == prs[i].JobAdvertisementId); if (temp != null) { temp.JobAdvertisementName = prs[i].JobAdvertisementName; temp.Post = prs[i].Post; } else { ext.JobAdvertisements.Add(prs[i]); } } prs = ext.JobAdvertisements.ToArray(); for (var i = 0; i < prs.Length; i++) { var temp = onlineJobSite.JobAdvertisements.FirstOrDefault(x => x.JobAdvertisementId == prs[i].JobAdvertisementId); if (temp == null) { db.Entry(prs[i]).State = EntityState.Deleted; } } } if (onlineJobSite.RegisterApplicants != null && onlineJobSite.RegisterApplicants.Count > 0) { var srvs = onlineJobSite.RegisterApplicants.ToArray(); for (var i = 0; i < srvs.Length; i++) { var temp = ext.RegisterApplicants.FirstOrDefault(c => c.RegisterApplicantId == srvs[i].RegisterApplicantId); if (temp != null) { temp.RegisterApplicantName = srvs[i].RegisterApplicantName; temp.ContactEmail = srvs[i].ContactEmail; } else { ext.RegisterApplicants.Add(srvs[i]); } } srvs = ext.RegisterApplicants.ToArray(); for (var i = 0; i < srvs.Length; i++) { var temp = onlineJobSite.RegisterApplicants.FirstOrDefault(x => x.RegisterApplicantId == srvs[i].RegisterApplicantId); if (temp == null) { db.Entry(srvs[i]).State = EntityState.Deleted; } } } try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OnlineJobSiteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool Update(JobAdvertisement ja) { db.Entry(ja).State = EntityState.Modified; return(db.SaveChanges() > 0); }