Example #1
0
        public T Add(T entity)
        {
            _domainDbContext.Set <T>().Add(entity);
            _domainDbContext.SaveChanges();

            return(entity);
        }
Example #2
0
        public async Task <IActionResult> Execute(int customerId, UpdateCustomerModel data)
        {
            var customer = await _db.Set <Customer>().SingleAsync(p => p.Id == customerId);

            customer.Update(name: data.Name);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Execute(int customerId, CreateVersionModel data)
        {
            var customer = await _db.Set <Customer>().SingleAsync(p => p.Id == customerId);

            customer.IncrementVersion(data.Message);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Execute(int customerId, int addressId, CreateAddressModel data)
        {
            var customer = await _db.Set <Customer>().Include(p => p.Addresses).SingleAsync(p => p.Id == customerId);

            customer.UpdateAddress(addressId: addressId,
                                   line: data.Line,
                                   suburb: data.Suburb,
                                   city: data.City,
                                   province: data.Province,
                                   code: data.Code);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Execute(int customerId, CreateAddressModel data)
        {
            var customer = await _db.Set <Customer>().Include(p => p.Addresses).SingleAsync(p => p.Id == customerId);

            var address = customer.AddAddress(
                line: data.Line,
                suburb: data.Suburb,
                city: data.City,
                province: data.Province,
                code: data.Code);
            await _db.SaveChangesAsync();

            var result = new CreateAddressResult {
                Id = address.Id
            };

            return(Ok(result));
        }
Example #6
0
        public async Task InsertAsync(T obj)
        {
            await _context.Set <T>().AddAsync(obj);

            await _context.SaveChangesAsync();
        }
Example #7
0
 public void Insert(T obj)
 {
     _context.Set <T>().Add(obj);
     _context.SaveChanges();
 }