Example #1
0
        public static ICustomer CustomerForInserting()
        {
            var first = FirstNames();
            var last = LastNames();
            var customer = new Customer(FirstNames())
                {
                    FirstName = first,
                    LastName = last,
                    Email = Email(first, last)
                };

            return customer;
        }
        public static ICustomer CustomerForInserting(string loginName = "")
        {
            loginName = string.IsNullOrEmpty(loginName) ? FirstNames() : loginName;
            var first = FirstNames();
            var last = LastNames();
            var customer = new Customer(loginName)
                {
                    FirstName = first,
                    LastName = last,
                    Email = Email(first, last)
                };

            return customer;
        }
        public static ICustomer CustomerForInserting()
        {
            var first = FirstNames();
            var last = LastNames();
            var customer = new Customer(0, 0, null)
                {
                    FirstName = first,
                    LastName = last,
                    Email = Email(first, last),
                    MemberId = null,
                    TotalInvoiced = 0
                };

            //customer.ResetDirtyProperties();

            return customer;
        }
Example #4
0
        /// <summary>
        /// Creates a customer and saves the record to the database
        /// </summary>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="email">the email address of the customer</param>
        /// <param name="memberId">The Umbraco member Id of the customer</param>
        /// <returns><see cref="ICustomer"/></returns>
        internal ICustomer CreateCustomerWithKey(string firstName, string lastName, string email, int? memberId = null)
        {
            var customer = new Customer(0, 0, null)
            {
                FirstName = firstName,
                LastName = lastName,
                Email = email,
                MemberId = memberId
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<ICustomer>(customer), this))
            {
                customer.WasCancelled = true;
                return customer;
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateCustomerRepository(uow))
                {
                    repository.AddOrUpdate(customer);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs<ICustomer>(customer), this);

            return customer;
        }
Example #5
0
        /// <summary>
        /// Creates a customer without saving to the database
        /// </summary>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="email">the email address of the customer</param>
        /// <param name="memberId">The Umbraco member Id of the customer</param>
        /// <returns><see cref="ICustomer"/></returns>
        internal ICustomer CreateCustomer(string firstName, string lastName, string email, int? memberId = null)
        {
            var customer = new Customer(0, 0, null)
                {
                    FirstName = firstName,
                    LastName = lastName,
                    Email = email,
                    MemberId = memberId
                };

            Created.RaiseEvent(new Events.NewEventArgs<ICustomer>(customer), this);

            return customer;
        }
Example #6
0
        /// <summary>
        /// Creates a customer and saves the record to the database
        /// </summary>
        /// <param name="loginName">
        /// The login Name.
        /// </param>
        /// <param name="firstName">
        /// The first name of the customer
        /// </param>
        /// <param name="lastName">
        /// The last name of the customer
        /// </param>
        /// <param name="email">
        /// the email address of the customer
        /// </param>
        /// <returns>
        /// <see cref="ICustomer"/>
        /// </returns>
        public ICustomer CreateCustomerWithKey(string loginName, string firstName, string lastName, string email)
        {
            Mandate.ParameterNotNullOrEmpty(loginName, "loginName");

            var customer = new Customer(loginName)
            {
                FirstName = firstName,
                LastName = lastName,
                Email = email
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<ICustomer>(customer), this))
            {
                customer.WasCancelled = true;
                return customer;
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateCustomerRepository(uow))
                {
                    repository.AddOrUpdate(customer);
                    uow.Commit();
                }
            }

            SaveAddresses(customer);

            Created.RaiseEvent(new Events.NewEventArgs<ICustomer>(customer), this);

            return customer;
        }
Example #7
0
        /// <summary>
        /// Creates a customer without saving to the database
        /// </summary>
        /// <param name="loginName">The login name of the customer.</param>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="email">the email address of the customer</param>
        /// <returns>The <see cref="ICustomer"/></returns>
        public ICustomer CreateCustomer(string loginName, string firstName, string lastName, string email)
        {
            Mandate.ParameterNotNullOrEmpty(loginName, "loginName");
            var customer = new Customer(loginName)
                {
                    FirstName = firstName,
                    LastName = lastName,
                    Email = email
                };

            if (!Creating.IsRaisedEventCancelled(new Events.NewEventArgs<ICustomer>(customer), this))
            {
                return customer;
            }

            customer.WasCancelled = true;

            return customer;
        }
        /// <summary>
        /// Updates an existing Customer
        /// 
        /// PUT /umbraco/Merchello/CustomerApi/PutCustomer
        /// </summary>
        /// <param name="customer"> To Update</param>
        /// <returns>Http Response</returns>
        public HttpResponseMessage PutCustomer(Customer customer)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                _customerService.Save(customer);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message));
            }
            return response;
        }