Exemplo n.º 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));
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 17
0
 public async Task Add(Customer customer)
 {
     await _customersRepository.Add(customer);
 }
Exemplo n.º 18
0
        public ICustomerModel Add(ICustomerModel model)
        {
            var customer = _mapper.Map <Customer>(model);

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