예제 #1
0
        public async Task <CommandResponse> Handle(CustomerAddCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                return(request.CommandResponse);
            }
            var customer = new Customer(Guid.NewGuid(), request.CompanyName, request.ContactName, request.ContactTitle,
                                        request.Email, request.Address, request.City, request.PostalCode, request.Country, request.Phone);

            var checkEmail = await _customersRepository.GetByEmail(customer.Email);

            if (checkEmail != null)
            {
                request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure("Email", "E-Mail Alreadt Exist"));
                return(request.CommandResponse);
            }

            // TODO Here will Add to Domain Event....

            customer.Apply(new CustomerAddEvent(customer.Id, customer.CompanyName, customer.ContactName, customer.ContactTitle,
                                                customer.Email, customer.Address, customer.City, customer.PostalCode, customer.Country, customer.Phone));

            // Create Db
            _customersRepository.Add(customer);

            // Create Event Store
            await _eventStoreRepository.SaveAsync <Customer>(customer);

            // Commit
            return(await Commit(_customersRepository.UnitOfWork));
        }
예제 #2
0
 public void Add(Customer customer)
 {
     if (_repository.GetCustomers().Where(obj => obj.Id == customer.Id).FirstOrDefault() != null)
     {
         throw new CustomerCollisionException("Id Collision of Customers");
     }
     _repository.Add(customer);
 }
예제 #3
0
        private async Task <Customer> CreateCustomer()
        {
            var customer = new Customer
                               (Guid.NewGuid(), "Alfreds Futterkiste", "Maria Anders", "Sales Representative", "*****@*****.**", "Obere Str. 57",
                               "Berlin", "12209", "Germany", "05420000000");

            _customersRepository.Add(customer);
            await _customersRepository.UnitOfWork.Commit();

            return(customer);
        }
예제 #4
0
        public async Task <ActionResult <CustomerDto> > CreateCustomer([FromBody] CustomerForCreationDto customer)
        {
            var customerToAdd = _mapper.Map <Customer>(customer);

            _customersRepository.Add(customerToAdd);
            await _customersRepository.SaveAsync();

            var customerToReturn = _mapper.Map <CustomerDto>(customerToAdd);

            return(CreatedAtAction(nameof(GetCustomer), new { customerId = customerToReturn.Id }, customerToReturn));
        }
예제 #5
0
 [Route("")] //[bazwoyAdresAplikaci}/api/customers
 public IActionResult Create([FromBody] Customer customer)
 {
     if (ModelState.IsValid)
     {
         var bookIdToBeSabed = _customerRepository.Add(customer);
         return(Ok(customer));
     }
     else
     {
         return(BadRequest());
     }
 }
예제 #6
0
        public ActionResult <Customer> Post([FromBody] Customer newCustomer)
        {
            int?newId = repo.Add(newCustomer);

            if (newId.HasValue && !string.IsNullOrEmpty(newCustomer.name))
            {
                return(CreatedAtAction(nameof(Get), new { id = newId }, newCustomer));
            }

            // failed...
            return(BadRequest(newCustomer));
        }
예제 #7
0
        public async Task <IHttpActionResult> PostCustomer(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            customer.Created = DateTime.Now;
            _customersRepository.Add(customer);

            return(Ok(customer));
        }
        public async Task Handle(CustomerWasCreated notification, CancellationToken cancellationToken)
        {
            var data = new CustomerData
            {
                DocumentNumber = $"{notification.Data.Document}",
                Name           = $"{notification.Data.Name}",
                BillingAddress = JsonConvert.SerializeObject(notification.Data.BillingAddress)
            };

            await Console.Out.WriteLineAsync($"{notification.Data.BillingAddress}");

            await _customersRepository.Add(data);
        }
예제 #9
0
        private int CreateCust(User usr)
        {
            Customer cust = new Customer();

            cust.CustName             = usr.UserName;
            cust.CustEmail            = usr.UserEmail;
            cust.CustCreatedByUserKey = 1;
            cust.CustCreatedDate      = DateTime.Now;
            string message = "";

            cust = custRepository.Add(cust, ref message);

            return(cust.CustKey);
        }
        public Customer CreateCustomer(string name, string lastName, string creditCardValue)
        {
            var fullName = FullName.Create(name, lastName);

            var isCreditCardValid = paymentService.CreditCardIsValid(creditCardValue);

            var creditCard = CreditCard.Create(creditCardValue, isCreditCardValid);

            var customer = Customer.Create(fullName, creditCard);

            customersRepository.Add(customer);

            return(customer);
        }
        internal void AddCustomerToDB(CustomersAddVM viewModel)
        {
            Customers customer = new Customers
            {
                FirstName        = viewModel.FirstName,
                LastName         = viewModel.LastName,
                PersonNumber     = viewModel.PersonNumber,
                KilometersDriven = 0,
                NumberOfOrders   = 0,
                MembershipLevel  = 0
            };

            customersRepository.Add(customer);
            eventsService.CreateAddedCustomerEvent(customer);
        }
        // POST api/Customers
        public IHttpActionResult Post([FromBody] Customer value)
        {
            try
            {
                _db.Add(value);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(nameof(Customer), ex.Message);

                return(BadRequest(ModelState));
            }

            return(Ok());
        }
예제 #13
0
        public ResponseModel <object> Save(Customers customers)
        {
            ResponseModel <object> response = new ResponseModel <object>();
            Customers customer = _customersRepository.Single(x => x.Email == customers.Email);

            if (customer != null)
            {
                response.IsSuccess = false;
                response.Message   = "Bu mail adresiyle daha önce kayıt yapılmış!";
                return(response);
            }
            _customersRepository.Add(customers);
            _unitOfWork.Complete();
            response.IsSuccess = true;
            return(response);
        }
        /// <summary>
        /// Takes a json string that represents a <c>Customer</c> object,
        /// Deserializes it into an actual <see cref="Customer"/> instance
        /// and adds it to the 'data store.'
        /// </summary>
        /// <param name="customer">
        /// An instance of the <c>Customer</c> object to be added to the data
        /// store.
        /// </param>
        /// <returns>
        /// The newly added Customer, or null if there was a problem.
        /// </returns>
        public Customer AddCustomer(Customer customer)
        {
            // "It is a bad practice to return the real model representation"
            // of course, but given limited time, I'm not trying to jump through ALL the hoops.

            try
            {
                _customersRepository.Add(customer);
            }
            catch (Exception oEx)
            {
                Debug.WriteLine(oEx);
                return(null);
            }

            return(customer);
        }
        public async Task <Unit> Handle(RegisterCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = Customer.Register(
                request.Id,
                request.FirstName,
                request.LastName,
                request.BirthDate,
                request.Email,
                request.Phone
                );

            await _repository.Add(customer);

            await _repository.SaveChanges();

            return(Unit.Value);
        }
예제 #16
0
        public object Post(Customer added)
        {
            object json;
            string messageError = "";

            try
            {
                Customer posted = repository.Add(added, ref messageError);

                if (posted != null)
                {
                    json = new
                    {
                        total   = 1,
                        data    = posted,
                        success = true
                    };
                }
                else
                {
                    json = new
                    {
                        message = messageError,
                        success = false
                    };
                };
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                json = new
                {
                    message = ex.Message,
                    success = false
                };
            };

            return(json);
        }
예제 #17
0
 public async Task Add(Customer customer)
 {
     await _customersRepository.Add(customer);
 }
예제 #18
0
        public ICustomerModel Add(ICustomerModel model)
        {
            var customer = _mapper.Map <Customer>(model);

            return(_mapper.Map <CustomerModel>(_repo.Add(customer)));
        }