예제 #1
0
        public IHttpActionResult Post(int id, [FromBody] Customer customer)
        {
            customer.Id = id;
            var newCustomer = _customerRepository.AddOrUpdate(customer);

            return(Ok(newCustomer));
        }
        public async Task Handle(CreateCustomer command)
        {
            log.Information($"Creating new customer: {command.FirstName} {command.LastName}");

            var          name         = new Name(command.FirstName, command.MiddleName ?? "", command.LastName);
            var          address      = new Address(command.AddressLine1, command.AddressLine2, command.City, command.State, command.ZipCode);
            EmailAddress emailAddress = command.EmailAddress;

            var newCustomer = Customer.Create(name, address, emailAddress, command.IsPreferredCustomer);

            await customerRepository.AddOrUpdate(newCustomer);

            log.Information($"Created new customer: {newCustomer.Name.FullName} with id {newCustomer.Id}");
        }
예제 #3
0
        public async Task <IActionResult> Edit(CustomerEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await _customerRepository.AddOrUpdate(new Customer()
            {
                Id          = model.Id,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                PhoneNumber = model.PhoneNumer,
                Email       = model.Email,
                IsAdult     = model.IsAdult
            });

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public virtual ActionResult Register(RegisterModel model, string returnUrl)
        {
            if (CustomerContext.Current.IsAuthenticated)
            {
                return(RedirectedAsync(returnUrl, Resources.Error_AlreadyLoggedIn, true));
            }

            if (model == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resources.Error_NotFound_Customer);
            }

            var dbCustomer = _customerRepository.GetByCellPhone(model.CellPhone);

            if (dbCustomer != null)
            {
                ModelState["CellPhone"].Errors.Add(string.Format(Resources.Validation_Duplicate, Resources.Members_Customer_CellPhone));
            }

            dbCustomer = _customerRepository.GetByEmail(model.Email);
            if (dbCustomer != null)
            {
                ModelState["Email"].Errors.Add(string.Format(Resources.Validation_Duplicate, Resources.Members_Customer_Email));
            }

            if (!ModelState.IsValid)
            {
                return(ViewAsync(Views.Register, Views._Register, model));
            }

            dbCustomer = model.ToCustomer();

            SecurityHelpers.UpdateCustomerPassword(dbCustomer, model.Password, false);

            _customerRepository.AddOrUpdate(dbCustomer);
            _customerRepository.SaveChanges();

            CustomerContext.Current.Customer = dbCustomer;

            //_notificationController.Registered(dbCustomer);

            return(RedirectedAsync(returnUrl, Resources.Success_Registered));
        }