コード例 #1
0
        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));
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 /// <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;
     //}
 }
コード例 #6
0
 public void Add(Appointment appointment)
 {
     _spaContext.Appointments.Add(appointment);
     _spaContext.SaveChanges();
 }
コード例 #7
0
 public void Add(ServiceProvider provider)
 {
     _spaContext.ServiceProviders.Add(provider);
     _spaContext.SaveChanges();
 }
コード例 #8
0
 //method allows me to add customers to my list
 public void Add(Customer customer)
 {
     _spaContext.Customers.Add(customer);
     _spaContext.SaveChanges();
 }
コード例 #9
0
 public void Add(TEntity obj)
 {
     Ctx.Set <TEntity>().Add(obj);
     Ctx.SaveChanges();
 }