Beispiel #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(Customer.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <Guid> Create(Customer aggregate, CancellationToken token)
        {
            var contactEntity = _mapper.Map <Contact, ContactEntity>(aggregate.Contact);
            var addressEntity = _mapper.Map <Address, AddressEntity>(aggregate.Address);
            var customer      = _mapper.Map <Customer, CustomerEntity>(aggregate);

            customer.AddressId = addressEntity.Id = Guid.NewGuid();
            customer.ContactId = contactEntity.Id = Guid.NewGuid();

            await _context.Addresses.AddAsync(addressEntity, token);

            await _context.Contacts.AddAsync(contactEntity, token);

            await _context.Customers.AddAsync(customer, token);

            await _context.SaveChangesAsync(token);

            return(aggregate.Id);
        }
Beispiel #3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Customer.Add(Customer);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Customer = await _context.Customer.FindAsync(id);

            if (Customer != null)
            {
                _context.Customer.Remove(Customer);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #5
0
        public async Task AddCustomer(Customer customer)
        {
            await _context.AddAsync(customer);

            await _context.SaveChangesAsync();
        }