Example #1
0
        public async Task <OperationResult <Customer> > CreateCustomerAsync(Customer customer)
        {
            if (!customer.Validate())
            {
                _logger.LogError($"Error: Invalid customer");
                return(OperationResult <Customer> .Failure("Error: Invalid customer"));
            }

            OperationResult <Customer> result;

            try
            {
                await _context.Customers.AddAsync(customer).ConfigureAwait(false);

                await _context.SaveChangesAsync().ConfigureAwait(false);

                result = OperationResult <Customer> .Success(customer);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Error: Cannot create customer");
                result = OperationResult <Customer> .Failure("Cannot create customer");
            }

            return(result);
        }
Example #2
0
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.ID)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #3
0
        public async Task <T> AddAsync(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Example #4
0
        public async Task <CustomerEntity> AddCustomer(CustomerEntity customer)
        {
            await _context.customers.AddAsync(customer);

            await _context.SaveChangesAsync();

            return(customer);
        }
        public async Task <Customer> AddCustomerAsync(Customer customer)
        {
            Validator.ValidateCustomerDetails(customer);

            var response = await _customerDbContext.AddAsync(customer);

            await _customerDbContext.SaveChangesAsync();

            return(response.Entity);
        }
        public async Task <bool> CreateAsync(CustomerEntity customer)
        {
            if (!IsIDExistsAsync(customer.CustomerCID).Result)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CountryCode")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
        public async Task InsertCustomerAsync(
            Domain.Models.Customer customer,
            CancellationToken cancellationToken = default)
        {
            var entity = MapToEntity(customer);

            _customerDbContext.Customers.Add(entity);

            await _customerDbContext
            .SaveChangesAsync(cancellationToken);
        }
        public async Task <CustomerDto> PostAsync(CustomerDto customerDto)
        {
            await _customerValidator.ValidateAndThrowAsync(customerDto);

            var customer        = _mapper.Map <Customer>(customerDto);
            var updatedCustomer = await _context.Customers.AddAsync(customer);

            await _context.SaveChangesAsync();

            return(_mapper.Map <CustomerDto>(updatedCustomer.Entity));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CountryId")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "CountryCode", city.CountryId);
            return(View(city));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Address,MobileNo,Email,CityId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", customer.CityId);
            return(View(customer));
        }
Example #12
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public async Task <ActionResult <Customer> > DeleteCustomer(Customer customer)
        {
            Customer customerToDelete = await _context.Customers.FindAsync(customer.Id);

            if (customerToDelete == null)
            {
                _logger.LogWarning("Error deleting customer Id " + customer.Id + " : " + customer.FirstName + " " + customer.Surname);
                return(NotFound());
            }

            _context.Customers.Remove(customerToDelete);
            await _context.SaveChangesAsync();

            return(customer);
        }
Example #14
0
        private async void btnAddNewTool_Click(object sender, EventArgs e)
        {
            using (var t = new Tool())
            {
                t.ShowDialog();

                if (t.Value == null)
                {
                    return;
                }

                DbContext.Tools.Add(t.Value);
                await DbContext.SaveChangesAsync();
            }
        }
Example #15
0
        public async Task <ActionResult <CustomerInfo> > PostCustomerData(CustomerInfo customerinfo)
        {
            _context.CustomerInfoData.Add(customerinfo);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCustomerData), new { id = customerinfo.CustomerID }, customerinfo));
        }
Example #16
0
        private async void sfDataGrid1_CellButtonClick(object sender, CellButtonClickEventArgs e)
        {
            var r = (Models.Order)sdgOrders.GetRecordAtRowIndex(e.RowIndex);

            if (r == null)
            {
                return;
            }

            var order = await DbContext.Orders.SingleOrDefaultAsync(o => o.Id == r.Id);

            switch (e.Column.HeaderText)
            {
            case "Reject":
                r.OrderStatus = OrderStatus.Rejected;
                break;

            case "Accept":
                r.OrderStatus = OrderStatus.Accepted;
                break;

            case "Delete":
                DbContext.Orders.Remove(r);
                break;
            }

            await DbContext.SaveChangesAsync();

            sdgOrders.Refresh();
        }
Example #17
0
        public async Task CreateCustomerAsync(CustomerDto customerCommand)
        {
            var customer = _mapper.Map <Data.Entities.Customer>(customerCommand);
            await _dbContext.Customers.AddAsync(customer);

            await _dbContext.SaveChangesAsync();
        }
        public async Task <HttpResponseMessage> CreateCustomer([FromBody] Customer customer)
        {
            try
            {
                System.Threading.Thread.Sleep(1000);//Delay simulation
                db.Customers.Add(customer);
                await db.SaveChangesAsync();

                response = Request.CreateResponse(HttpStatusCode.OK, customer);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.ExpectationFailed, ex.ToString());
            }

            return(response);
        }
        public async Task Handle(ClientCreateCommand notification, CancellationToken cancellationToken)
        {
            logger.LogInformation($"---Stared ClientCreateEventHandler's handler");

            var client = notification.MapTo <Client>();

            await dbContext.AddAsync(client);

            await dbContext.SaveChangesAsync();
        }
        public async Task <ActionResult <Customer> > AddCustomerAsync([FromBody] CustomerRequest request)
        {
            Customer newCustomer;

            try
            {
                var nextCustId = _dbContext.Customers.Any() ? _dbContext.Customers.Max(c => c.Id) + 1 : 1;

                newCustomer = request.ToCustomer(nextCustId);

                _dbContext.Customers.Add(newCustomer);
                await _dbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            return(newCustomer);
        }
Example #21
0
        public override async Task ProcessAsync(CancellationToken cancellationToken)
        {
            foreach (ECommerce.Customer customer in GetCustomersToCreate())
            {
                var customerEntity = MapToEntity(customer);

                await _dbContext.Customers.AddAsync(customerEntity, cancellationToken);

                await _dbContext.SaveChangesAsync(cancellationToken);
            }
        }
Example #22
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
Example #23
0
        public async Task Handle(UserCreatedEvent userEvent)
        {
            await _repository.Add(new Customer
            {
                Id        = userEvent.Id,
                Email     = userEvent.Email,
                FirstName = userEvent.FirstName,
                LastName  = userEvent.LastName
            });

            await _dbContext.SaveChangesAsync();
        }
Example #24
0
        public async Task <IActionResult> OnPostDeleteAsync(int id)
        {
            var contact = await _context.Customers.FindAsync(id);

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

            return(RedirectToPage());
        }
Example #25
0
        public async Task <bool> AddCustomer(CustomerDbContext context, Customer customer)
        {
            var hasExisting = CheckIfRecordAlreadyExists(context.CustomerItems.ToList(), customer.FirstName);

            if (hasExisting)
            {
                return(false);
            }
            context.Add(customer);
            await context.SaveChangesAsync();

            return(true);
        }
Example #26
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            Message = $"Customer {Customer.Name} added";
            return(RedirectToPage("./IndexPeek2"));
        }
Example #27
0
        public async Task <IActionResult> PutCustomer([FromRoute] int id, [FromBody] Customer customer)
        {
            customer.id      = id;
            customer.Country = _context.Country.Single(c => c.CountryId == customer.Country.CountryId);
            _context.Entry(customer).State = EntityState.Modified;

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

            return(NoContent());
        }
        // This method we define for use or call Post Method
        public async Task <IActionResult> OnPostAsync()
        {
            // always validate your data field ( Id and Name)
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // save into the db context reference
            _dbContext.Customers.Add(Customer);
            // save also in DB
            await _dbContext.SaveChangesAsync();

            // . represent the main root of folder (Pages)
            return(RedirectToPage("./Index"));
        }
Example #29
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Customer).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new Exception($"Customer {Customer.Id} not trouvé.");
            }

            return(RedirectToPage("./Index"));
        }
        public async Task Initialize(CustomerDbContext context)
        {
            context.Customers.Add(new Customer()
            {
                Name = "Phil Collins", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "Tony Banks", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "Mike Rutherford", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "Chester Thompson", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "Daryl Stuermer", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "Mark Knopfler", Created = DateTime.Now
            });

            context.Customers.Add(new Customer()
            {
                Name = "David Knopfler", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "John Illsley", Created = DateTime.Now
            });
            context.Customers.Add(new Customer()
            {
                Name = "Pick Withers", Created = DateTime.Now
            });

            await context.SaveChangesAsync();
        }