Beispiel #1
0
 public Customer(Domain.Customers.Customer customer, IEnumerable <Guid> accounts)
 {
     this.Id       = customer.Id;
     this.Name     = customer.Name;
     this.PIN      = customer.PIN;
     this.Accounts = new AccountCollection(accounts);
     this.Version  = customer.Version;
 }
Beispiel #2
0
        public async Task Handle(GetCustomerDetaisCommand message)
        {
            Domain.Customers.Customer customer = await this.customerReadOnlyRepository.Get(message.CustomerId);

            CustomerResponse response = responseConverter.Map <CustomerResponse>(customer);

            outputBoundary.Populate(response);
        }
Beispiel #3
0
        public async Task <CustomerResult> Process(UpdateCustomerCommand command)
        {
            Domain.Customers.Customer customer = new Domain.Customers.Customer(command.CustomerId, command.Name, command.LastName, command.Document, command.Celphone, command.Address);

            await customerWriteOnlyRepository.Update(customer);

            CustomerResult customerResult = resultConverter.Map <CustomerResult>(customer);

            return(customerResult);
        }
Beispiel #4
0
        public IActionResult CalculateRebate([FromBody] OrderDto newOrder)
        {
            if (newOrder == null)
            {
                return(BadRequest());
            }

            Customer selectedCustomer = _customerRepository.GetEntity(newOrder.CustomerId);
            Product  selectedProduct  = _productRepository.GetEntity(newOrder.ProductId);

            if (selectedCustomer == null)
            {
                return(BadRequest(ModelState));
            }

            if (selectedProduct == null)
            {
                return(BadRequest(ModelState));
            }

            // Here we should use a Mapper between two similar or almost similar models. For the moment it's done by hand.
            Domain.Products.Product mappedProduct = new Domain.Products.Product()
            {
                Id     = selectedProduct.Id,
                Name   = selectedProduct.Name,
                Price  = selectedProduct.Price,
                OnSale = selectedProduct.OnSale
            };

            Domain.Customers.Customer mappedCustomer = new Domain.Customers.Customer()
            {
                Id                  = selectedProduct.Id,
                Name                = selectedProduct.Name,
                IsPremium           = selectedCustomer.IsPremium,
                DateOfFirstPurchase = selectedCustomer.DateOfFirstPurchase
            };

            Order order = new Order()
            {
                Product   = mappedProduct,
                Customer  = mappedCustomer,
                Quantity  = newOrder.Quantity,
                UnitPrice = mappedProduct.Price
            };

            var resultDiscount = _discountCalculator.CalculateDiscountPercentage(order);
            var returnedValue  = new JsonResult(resultDiscount);

            // return new JsonResult(resultDiscount)

            return(Ok(resultDiscount));
        }
        public async Task <ICustomer> GetCustomer(Guid id)
        {
            var user = userManager.FindByIdAsync(id.ToString());

            Domain.Customers.Customer customer = new Domain.Customers.Customer(Guid.Parse(user.Result.Id), new SSN(user.Result.SSN), new Name(user.Result.UserName));

            var accounts = mangaContext.Accounts
                           .Where(e => e.CustomerId == id)
                           .Select(e => e.Id)
                           .ToList();

            customer.LoadAccounts(accounts);

            return(customer);
        }
Beispiel #6
0
            public async Task HandleAsync(ChangeMarginCommand command)
            {
                var customer = await _customerReadRepository.Get(command.ComandData.TenantId);

                if (customer == null)
                {
                    customer = new Domain.Customers.Customer
                    {
                        Id         = command.ComandData.TenantId,
                        CreateDate = DateTime.Now,
                        Margin     = command.ComandData.Data.Margin
                    };

                    await _customerWriteRepository.Add(customer);
                }
                else
                {
                    customer.Margin = command.ComandData.Data.Margin;
                    await _customerWriteRepository.Update(customer);
                }
            }
        private void CreateCustomer()
        {
            var admin = _context.Customer.FirstOrDefault(e => e.LoginName == "admin");

            if (admin == null)
            {
                var rd = Common.CommonHelper.GenerateCode(length: 8);
                admin = new Domain.Customers.Customer
                {
                    LoginName      = "admin",
                    CustomerRoleId = _context.CustomerRole.FirstOrDefault(r => r.RoleName == "系统管理员").Id,
                    Email          = "*****@*****.**",
                    Mobile         = "18012341234",
                    Password       = Common.CommonHelper.CreatePasswordHash("admin", rd),
                    PasswordSalt   = rd,
                    Deleted        = false,
                    LastIpAddress  = "127.0.0.1",
                };
            }

            _context.Customer.Add(admin);
            _context.SaveChanges();
        }
        private void CreateCustomer()
        {
            var admin = _context.Customer.FirstOrDefault(e => e.Mobile == "18503223172");

            if (admin == null)
            {
                admin = new Domain.Customers.Customer
                {
                    CustomerRoleId       = (int)CustomerRole.System,
                    Mobile               = "18503223172",
                    PasswordSalt         = "WPIUEZ",
                    Password             = "******",
                    CreationTime         = DateTime.Now,
                    LastModificationTime = DateTime.Now,
                    OpenId               = "",
                    NickName             = "",
                    Promoter             = 0,
                };
            }

            _context.Customer.Add(admin);
            _context.SaveChanges();
        }
Beispiel #9
0
        public ActionResult Register(RegisterModel model, bool captchaValid)
        {
            if (model.EnabledCaptcha && !captchaValid)
            {
                ModelState.AddModelError("", "验证码错误");
            }
            var key           = string.Format(NetCommunitySolutionConsts.CACHE_SETTINGS, "common");
            var commonSetting = _cacheManager.GetCache(key).Get(key, () => _settingService.GetCommonSettings());

            if (!commonSetting.IsOpenRegistration)
            {
                return(RedirectToAction("RegisterClose"));
            }

            if (model.RegisterMode == RegistrationMode.Email)
            {
                if (String.IsNullOrWhiteSpace(model.Email))
                {
                    ModelState.AddModelError("", "请输入Email");
                }
                model.LoginName = model.Email;
            }

            if (model.RegisterMode == RegistrationMode.UserName)
            {
                if (String.IsNullOrWhiteSpace(model.LoginName))
                {
                    ModelState.AddModelError("", "请输入登录名");
                }
            }
            if (model.RegisterMode == RegistrationMode.Mobile)
            {
                if (String.IsNullOrWhiteSpace(model.Phone))
                {
                    ModelState.AddModelError("", "请输入手机号码");
                }
                model.LoginName = model.Phone;
            }
            if (!model.Password.Equals(model.ConfirmPassword))
            {
                ModelState.AddModelError("", "两次密码输入的不相同");
            }

            if (ModelState.IsValid)
            {
                var salt     = CommonHelper.GenerateCode(6);
                var password = _encryptionService.CreatePasswordHash(model.Password, salt);
                var customer = new Domain.Customers.Customer
                {
                    LoginName            = model.LoginName,
                    Mobile               = model.Phone,
                    Email                = model.Email,
                    CustomerRoleId       = (int)CustomerRole.Member,
                    Level                = 0,
                    NickName             = "",
                    Password             = password,
                    PasswordSalt         = salt,
                    CreationTime         = DateTime.Now,
                    LastModificationTime = DateTime.Now,
                    VerificatExpiryTime  = DateTime.Now,
                };
                customer.Id = _customerService.CreateCustomer(customer);

                var dto      = customer.MapTo <CustomerDto>();
                var identity = _loginManager.CreateUserIdentity(dto);
                AuthenticationManager.SignIn(new AuthenticationProperties {
                    IsPersistent = false
                }, identity);
                return(RedirectToAction("Index", "Home"));
            }

            var customerSetting = _cacheManager.GetCache(string.Format(NetCommunitySolutionConsts.CACHE_SETTINGS, "customer"))
                                  .Get(string.Format(NetCommunitySolutionConsts.CACHE_SETTINGS, "customer"),
                                       () => _settingService.GetCustomerSettings());

            model.EnabledCaptcha = customerSetting.EnabledCaptcha;
            model.CaptchaName    = customerSetting.CaptchaName;
            return(View(model));
        }