public IHttpActionResult PutDepartment(int id, Department department) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != department.Id) { return(BadRequest()); } db.Entry(department).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Put([FromBody] double value) { var draw = value; var ret = _context.AcctItems.Find(keyFind); if (ret != null) { ret.Credit -= draw; ret.Balance += draw; _context.AcctItems.Update(ret); _context.SaveChanges(); } }
public BankController(SpaContext context) { _context = context; _contextSeed = context; if (_contextSeed.AcctItems.Count() == 0) { _contextSeed.AcctItems.Add(new AccountModel { Id = key++, CustomerId = 1, Balance = 0.00, Credit = 100000.00 }); // _context.AcctItems.Add(new AccountModel { Id = 2, CustomerId = 1, Balance = 2.00, Credit = 200000.00 }); _contextSeed.SaveChanges(); } }
public static SpaContext GetContextWithData() { var options = new DbContextOptionsBuilder <SpaContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new SpaContext(options); context.Tasks.AddRange( new TaskBuilder().WithName("Some name1").WithDescription("Test desc1").Build(), new TaskBuilder().WithName("Some name2").WithDescription("Test desc2").Build(), new TaskBuilder().WithName("Completed task3").WithDescription("Test desc5").WithCompleted(true).Build(), new TaskBuilder().WithName("Some name4").WithDescription("Test desc4").Build(), new TaskBuilder().WithName("Deleted task5").WithDescription("Test desc5").WithDeleted(true).Build()); context.SaveChanges(); return(context); }
/// <summary> /// Saves the changes by calling "SaveChanges()" on DbContext /// </summary> /// <returns>Status</returns> public int Complete() { //try //{ return(_context.SaveChanges()); //} //catch (DbEntityValidationException e) //{ // foreach (var eve in e.EntityValidationErrors) // { // Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", // eve.Entry.Entity.GetType().Name, eve.Entry.State); // foreach (var ve in eve.ValidationErrors) // { // Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", // ve.PropertyName, ve.ErrorMessage); // } // } // throw; //} }
public void Add(Appointment appointment) { _spaContext.Appointments.Add(appointment); _spaContext.SaveChanges(); }
public void Add(ServiceProvider provider) { _spaContext.ServiceProviders.Add(provider); _spaContext.SaveChanges(); }
//method allows me to add customers to my list public void Add(Customer customer) { _spaContext.Customers.Add(customer); _spaContext.SaveChanges(); }
public void Add(TEntity obj) { Ctx.Set <TEntity>().Add(obj); Ctx.SaveChanges(); }