public IHttpActionResult Edit(TjCustomer model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { var entity = _dbContext.TjCustomers.FirstOrDefault(x => x.Id == model.Id); if (entity == null) { response.SetFailed("该客户不存在"); return(Ok(response)); } entity.Name = model.Name; entity.Phone = model.Phone; entity.Email = model.Email; entity.Company = model.Company; entity.Region = model.Region; entity.Location = model.Location; entity.Industry = model.Industry; entity.Owner = AuthContextService.CurrentUser.UserId; _dbContext.SaveChanges(); response = ResponseModelFactory.CreateInstance; return(Ok(response)); } }
public IHttpActionResult PostTjCustomer(TjCustomer tjCustomer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TjCustomers.Add(tjCustomer); try { db.SaveChanges(); } catch (DbUpdateException) { if (TjCustomerExists(tjCustomer.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = tjCustomer.Id }, tjCustomer)); }
public IHttpActionResult PutTjCustomer(int id, TjCustomer tjCustomer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tjCustomer.Id) { return(BadRequest()); } db.Entry(tjCustomer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TjCustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetTjCustomer(int id) { TjCustomer tjCustomer = db.TjCustomers.Find(id); if (tjCustomer == null) { return(NotFound()); } return(Ok(tjCustomer)); }
public IHttpActionResult Create(TjCustomer customer) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { customer.Owner = AuthContextService.CurrentUser.UserId; _dbContext.TjCustomers.Add(customer); _dbContext.SaveChanges(); } response.SetSuccess(); return(Ok(response)); }
public IHttpActionResult DeleteTjCustomer(int id) { TjCustomer tjCustomer = db.TjCustomers.Find(id); if (tjCustomer == null) { return(NotFound()); } db.TjCustomers.Remove(tjCustomer); db.SaveChanges(); return(Ok(tjCustomer)); }