public DistributorController(AppDbContext context, DistributorService distributorService, ProductService productService, TankService tankService)
 {
     _context            = context;
     _distributorService = distributorService;
     _productService     = productService;
     _tankService        = tankService;
 }
Beispiel #2
0
        public IMessageProvider Save()
        {
            var serialNo    = SerialNoHelper.Create();
            var distributor = DistributorService.GetById(DistributorId);

            if (distributor != null)
            {
                var owner = MembershipService.GetUserById(distributor.UserId) as DistributorUser;

                if (owner == null)
                {
                    AddError(LogTypes.DistributorEdit, "noOwner");
                    return(this);
                }

                owner.DisplayName = DisplayName;

                if (!string.IsNullOrEmpty(Password))
                {
                    owner.SetPassword(Password);
                }
                OnSave(distributor, owner);

                DistributorService.Update(distributor);
                UpdateAccountLevelPolicy(distributor);
                MembershipService.UpdateUser(owner);
                AddMessage("success", owner.Name);
                Logger.LogWithSerialNo(LogTypes.DistributorEdit, serialNo, distributor.DistributorId, owner.Name);
                CacheService.Refresh(CacheKeys.PosKey);
            }
            return(this);
        }
Beispiel #3
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            string distributorName = (this.distributorsDatagrid.SelectedItem as Distributor).Name;

            DistributorService.DeleteDistributor(distributorName);
            distributorsDatagrid.DataContext = DistributorService.GetAllDistributors();
        }
Beispiel #4
0
        public void TestMethod1()
        {
            GenericUnitOfWork  uow = new GenericUnitOfWork();
            DistributorService distributorService = new DistributorService(uow);
            bool SavedAll = distributorService.AddRange(new List <_Distributor>()
            {
                new _Distributor()
                {
                    DistributorName        = "Cty ABC",
                    RegionId               = 34,
                    DistributorAddress     = "552 Quang Trung, Go Vap, TP Ho Chi Minh",
                    DistributorEmail       = "*****@*****.**",
                    DistributorPhoneNumber = "0120000001",
                    Status      = "Cooperating",
                    Description = "No Describe anymore"
                },
                new _Distributor()
                {
                    DistributorName        = "Cty XYZ",
                    RegionId               = 48,
                    DistributorAddress     = "789 Nguyễn Huệ, Đống Đa, TP Hà Nội",
                    DistributorEmail       = "*****@*****.**",
                    DistributorPhoneNumber = "0120000002",
                    Status      = "Cooperating",
                    Description = "No Describe anymore"
                },
            });

            Assert.AreEqual(true, SavedAll);
        }
        private void AddDistributorsToViewList()
        {
            var viewListDataDistributors = new ObservableCollection <Distributor>();

            viewListDataDistributors             = DistributorService.GetAllDistributors();
            this.ListBoxDistributors.ItemsSource = viewListDataDistributors;
        }
Beispiel #6
0
        public ResultMsg Delete(int id)
        {
            ResultMsg msg = new ResultMsg();

            try
            {
                TransactionHelper.BeginTransaction();
                var distributor = DistributorService.GetById(id);
                if (distributor != null)
                {
                    //把下属经销商的上级设为要删除的经销商的上级。
                    List <Distributor> list = DistributorService.GetByParentId(id);
                    foreach (var item in list)
                    {
                        if (item != null)
                        {
                            //var user1 = MembershipService.GetUserById(item.UserId);
                            item.ParentId = distributor.ParentId;
                            //TransactionHelper.BeginTransaction();
                            // MembershipService.DeleteUser(user1);
                            DistributorService.Update(item);

                            Logger.LogWithSerialNo(LogTypes.DistributorEdit, SerialNoHelper.Create(), id, item.Name);
                            AddMessage("update.success", item.Name);
                            //TransactionHelper.Commit();

                            CacheService.Refresh(CacheKeys.DistributorKey);
                        }
                    }
                    var accounts = AccountService.Query(new AccountRequest()).Where(x => x.DistributorId == id);
                    foreach (var account in accounts)
                    {
                        account.DistributorId = distributor.ParentId;
                        AccountService.Update(account);
                    }
                    var user = MembershipService.GetUserById(distributor.UserId);
                    MembershipService.DeleteUser(user);
                    DistributorService.Delete(distributor);

                    Logger.LogWithSerialNo(LogTypes.DistributorDelete, SerialNoHelper.Create(), id, user.Name);
                    //AddMessage("delete.success", user.Name);
                    msg.Code     = 1;
                    msg.CodeText = "删除 " + user.DisplayName + " 成功";
                    TransactionHelper.Commit();

                    CacheService.Refresh(CacheKeys.PosKey);
                }
                else
                {
                    msg.CodeText = "不好意思,没有找到经销商";
                }
                return(msg);
            }
            catch (Exception ex)
            {
                msg.CodeText = "不好意思,系统异常";
                Logger.Error("删除经销商", ex);
                return(msg);
            }
        }
 public TankDistributorController(AppDbContext context, TankDistributorService tankDistributorService, TankService tankService, DistributorService distributorService)
 {
     _context = context;
     _tankDistributorService = tankDistributorService;
     _tankService            = tankService;
     _distributorService     = distributorService;
 }
Beispiel #8
0
        public ResultMsg SetDistributorId(int id, int distributor)
        {
            ResultMsg msg = new ResultMsg();

            try
            {
                Account item   = AccountService.GetById(id);
                int[]   status = { AccountStates.Created, AccountStates.Initialized, AccountStates.Ready };
                var     dis    = DistributorService.GetById(distributor);
                if (item != null && status.Contains(item.State) && dis != null)
                {
                    item.DistributorId = distributor;
                    AccountService.Update(item);

                    Logger.LogWithSerialNo(LogTypes.AdminUserEdit, SerialNoHelper.Create(), id, item.Name);
                    msg.Code     = 1;
                    msg.CodeText = item.Name + " 设置经销商成功成功";
                }
                else
                {
                    msg.CodeText = "所选择的经销商无效或者当前卡状态不能转换经销商";
                }
                return(msg);
            }
            catch (Exception ex)
            {
                msg.CodeText = "不好意思,系统异常";
                Logger.Error("设置经销商", ex);
                return(msg);
            }
        }
 public override void Given()
 {
     base.Given();
     this.Subject     = new DistributorService(this.MockedSmsService, this.MockedMailService, this.MockedMailFactory);
     this.Badge       = new List <Badge>(DomainStubFactory.CreateOwner().Badges)[0];
     this.Declaration = DomainStubFactory.CreateDeclaration(Badge);
 }
Beispiel #10
0
        public void EditOneRecord_ShouldBeUpdated()
        {
            var updatedItem = new Distributor
            {
                // specific id from TestDataSource.cs
                Id       = Guid.Parse("617dba9d-391b-4ca7-aeeb-0703ca526709"),
                FullName = "Zombie Killer",
                Status   = 3
            };
            IDistributorService service = new DistributorService();
            var response = service.Update(new List <Distributor> {
                updatedItem
            });

            Assert.IsTrue(response.Status == StatusFlag.Success);

            // Make sure the data already be updated
            var distResponse = service.GetById(new List <Guid> {
                updatedItem.Id
            });
            var distributor = ((List <Distributor>)distResponse.Data).FirstOrDefault();

            Assert.AreEqual(updatedItem.FullName, distributor.FullName);
            Assert.AreEqual(updatedItem.Status, distributor.Status);
        }
Beispiel #11
0
 protected override MsmqListener CreateListener(DistributorService distributorService, int timerInterval, string msmqPath)
 {
     if (this.QueueListener != null)
     {
         return(this.QueueListener);
     }
     return(new MockMsmqListener(distributorService, timerInterval, msmqPath));
 }
Beispiel #12
0
        public IEnumerable <ValidationError> Validate()
        {
            var distributor = DistributorService.GetById(InnerObject.DistributorId) as Distributor;

            if (!string.IsNullOrWhiteSpace(Mobile.Value1) && MembershipService.GetUserByMobile <DistributorUser>(this.Mobile.Value1, distributor.UserId).Count() > 0)
            {
                yield return(new ValidationError("Mobile", string.Format(Localize("messages.duplicationMobile"), Mobile.Value1)));
            }
        }
        protected override MsmqListener CreateListener(DistributorService distributorService, int timerInterval, string msmqPath)
        {
            if (this.QueueListener != null)
            {
                return this.QueueListener;
            }

            return new MockMsmqListener(distributorService, timerInterval, msmqPath);
        }
 public void SetUp()
 {
     productService     = new DefaultProductService();
     stockLevelService  = new DefaultStockLevelService();
     warehouseService   = new DefaultWarehouseService();
     distributorService = new DefaultDistributorService();
     applicationContext = new ApplicationContext();
     applicationContext.Init();
 }
Beispiel #15
0
        public void Ready()
        {
            var         q           = DistributorService.Query();
            UserRequest user        = new UserRequest();
            var         users       = MembershipService.QueryUsers <DistributorUser>(user).ToList();
            var         currentuser = this.SecurityHelper.GetCurrentUser();

            if (currentuser is AdminUserModel)
            {
                ////张飞牛肉,需要总部可以看到所有的经销商。
                ////如果是系统总部,列表中只包含一级经销商。
                //var distributors = DistributorService.Query().Where(x => x.ParentId == 0).ToList();
                //var list = (from x in (distributors.Where(x => users.Any(u => u.UserId == x.UserId)).ToList()) select new ListDistributor(x) { Owner = users.First(u => u.UserId == x.UserId) }).ToList();
                //var qq = (from x in list select new IdNamePair { Key = x.DistributorId, Name = x.DisplayName }).ToList();
                //Distributor.Bind(qq, true);
                var distributors = DistributorService.Query().ToList();
                var list         = (from x in (distributors.Where(x => users.Any(u => u.UserId == x.UserId)).ToList())select new ListDistributor(x)
                {
                    Owner = users.First(u => u.UserId == x.UserId)
                }).ToList();
                var qq           = (from x in list select new IdNamePair {
                    Key = x.DistributorId, Name = x.DisplayName
                }).ToList();
                Distributor.Bind(qq, true);
            }
            else if (currentuser is DistributorUserModel)
            {
                int id       = ((DistributorUserModel)currentuser).DistributorId;
                var totalIds = q.Select(x => x.DistributorId).ToList();
                var ids      = GetChildrenDistributorId(id, totalIds);
                //ids.Add(id);
                var distributors = from c in DistributorService.Query().ToList() where ids.Contains(c.DistributorId) select c;
                var list         = (from x in (distributors.Where(x => users.Any(u => u.UserId == x.UserId)).ToList())select new ListDistributor(x)
                {
                    Owner = users.First(u => u.UserId == x.UserId)
                }).ToList();
                var qq           = (from x in list select new IdNamePair {
                    Key = x.DistributorId, Name = x.DisplayName
                }).ToList();
                Distributor.Bind(qq, true);
            }
            else
            {
                List <IdNamePair> qq = new List <IdNamePair>();
                Distributor.Bind(qq, true);
            }

            List <IdNamePair> qs = new List <IdNamePair>();

            qs.Insert(0, new IdNamePair {
                Key = 0, Name = "未结算"
            });
            qs.Insert(0, new IdNamePair {
                Key = 1, Name = "已结算"
            });
            State.Bind(qs, true);
        }
Beispiel #16
0
 public void SetUp()
 {
     productService     = new DefaultProductService();
     distributorService = new DefaultDistributorService();
     qrcodeService      = new DefaultQrCodeService();
     bindingService     = new DefaultBindingService();
     applicationContext = new ApplicationContext();
     applicationContext.ConfigureHibernateMapping();
 }
Beispiel #17
0
        public void Read(int id)
        {
            var distributor = DistributorService.GetById(id);

            if (distributor != null)
            {
                var owner = MembershipService.GetUserById(distributor.UserId) as DistributorUser;
                SetInnerObject(distributor, owner);
            }
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var    newDistributor = this.DataContext as Distributor;
            string chosenTown     = this.cbTowns.SelectedItem.ToString();

            DistributorService.AddDistributor(newDistributor, chosenTown, _checkedBreweries);
            this.Close();
            //MainWindow mainWindow = new MainWindow();
            //mainWindow.Show();
        }
Beispiel #19
0
        public void GetAllDistributor_Valid()
        {
            //arrange
            IDistributorService service = new DistributorService();

            //Act
            var actual = service.GetAllDistributors();

            //Assert
            Assert.AreEqual(3, actual.Count);
        }
Beispiel #20
0
        /// <summary>
        /// 确认结算,如果这条消费记录的卡号不属于自己的,则给下级经销商生成结算请求
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public void Close(int id)
        {
            TransactionHelper.BeginTransaction();
            var item = DistributorBrokerageService.GetDistributorBrokerageById(id);

            if (item == null)
            {
                return;
            }
            var user      = this.SecurityHelper.GetCurrentUser();
            int currentId = -1;

            if (user is DistributorUserModel)
            {
                currentId = DistributorService.GetByUserId(user.CurrentUser.Id).DistributorId;
            }
            if (item.settlementDistributorId == currentId && item.status == false)
            {
                item.status = true;
                DistributorBrokerageService.UpdateDistributorBrokerage(item);
                //增加经销商的余额
                var distributor1 = DistributorService.GetById(item.settlementDistributorId);
                distributor1.Amount += item.brokerage;
                DistributorService.Update(distributor1);
                if (item.DistributorId != item.settlementDistributorId)
                {
                    //归属他下属的卡消费,他要跟下属结算。
                    //如果是多级还要找到他的直接下属,只能向他的直接下属发起结算请求。
                    int underId = GetDirectlyUnder(item.settlementDistributorId, item.DistributorId);
                    if (underId != 0)
                    {
                        var distributor            = DistributorService.GetAccountLevelPolicyRates(underId).FirstOrDefault();
                        DistributorBrokerage model = new DistributorBrokerage();
                        model.DistributorId           = item.DistributorId;
                        model.AccountId               = item.AccountId;
                        model.Bdate                   = item.Bdate;
                        model.consume                 = item.consume;
                        model.Edate                   = item.Edate;
                        model.settlementDistributorId = underId;
                        model.Rate      = distributor.Rate;
                        model.brokerage = item.consume * distributor.Rate;
                        model.status    = false;
                        DistributorBrokerageService.CreateDistributorBrokerage(model);
                    }
                    AddMessage("update.success", item.Id);
                }
            }
            else
            {
                AddError("不是结算经销商", item.Id);
            }
            TransactionHelper.Commit();
        }
Beispiel #21
0
        public void InsertNewRecordWithOutrangeStatus_ShouldError()
        {
            var newItem = new Distributor
            {
                FullName = "Mikocok",
                Status   = 127
            };
            IDistributorService service = new DistributorService();
            var response = service.Add(newItem);

            Assert.IsTrue(response.Status == StatusFlag.Error);
        }
Beispiel #22
0
        private void AddDistributorsToComboBox()
        {
            ObservableCollection <string> distributorsList = new ObservableCollection <string>();

            distributorsList = DistributorService.GetAllDistributorsNames();
            if (distributorsList.Count != 0 && _beerForEdit.Distributor != null)
            {
                cbDistributors.SelectedIndex = distributorsList.IndexOf(_beerForEdit.Distributor.Name);
                //townList.Add("Add New Town...");
                this.cbDistributors.ItemsSource = distributorsList;
            }
        }
Beispiel #23
0
        public void InsertNewRecordWithEmptyFullName_ShouldError()
        {
            var newItem = new Distributor
            {
                FullName = null,
                Status   = 2
            };
            IDistributorService service = new DistributorService();
            var response = service.Add(newItem);

            Assert.IsTrue(response.Status == StatusFlag.Error);
        }
Beispiel #24
0
        public void EditRecordWithEmptyItem_ShouldError()
        {
            var listItem = new List <Distributor>();
            IDistributorService service = new DistributorService();
            var response = service.Update(listItem);

            Assert.IsTrue(response.Status == StatusFlag.Error);

            var response2 = service.Update(null);

            Assert.IsTrue(response.Status == StatusFlag.Error);
        }
Beispiel #25
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            string distributorName = SearchTextBox.Text.Trim();

            if (distributorName == null || distributorName.Length == 0)
            {
                WarningLabel.Visibility = Visibility.Visible;
                WarningLabel.Content    = "Beer name cannot be empty.";
                return;
            }

            distributorsDatagrid.DataContext = DistributorService.GetDistributorsByName(distributorName);
        }
        public IDistributorService Create()
        {
            this._delegatingHandlers.Add(new OnProblemDetailsHandler());

            var client = new DistributorService(
                this._configuration.Uri,
                this._configuration.Credentials,
                this._delegatingHandlers.ToArray());

            client.SetRetryPolicy(new RetryPolicy(new HttpStatusCodeErrorDetectionStrategy(), this._configuration.RetryCount));

            return(client);
        }
Beispiel #27
0
        public void GetAll_ShouldReturnItems()
        {
            // The Order is Matter! this method should be on top.
            IDistributorService service = new DistributorService();
            var response = service.GetAll();

            Assert.IsTrue(response.Status == StatusFlag.Success);

            // We know from TestDataSource.cs
            var dataList = (List <Distributor>)response.Data;

            Assert.AreEqual(3, dataList.Count);
        }
Beispiel #28
0
        public void Query(out string pageHtml)
        {
            pageHtml = string.Empty;
            var query   = DistributorService.Query().ToList();
            var request = new UserRequest();

            if (request.PageIndex == null || request.PageIndex <= 0)
            {
                request.PageIndex = 1;
            }
            if (request.PageSize == null || request.PageSize <= 0)
            {
                request.PageSize = 10;
            }
            if (!string.IsNullOrEmpty(this.Name))
            {
                request.NameWith = Name;
            }
            var users = MembershipService.QueryUsers <DistributorUser>(request).ToList();
            var user  = this.SecurityHelper.GetCurrentUser();
            int pid   = 0;

            if (user is DistributorUserModel)
            {
                pid   = ((DistributorUserModel)user).DistributorId;
                query = query.Where(x => users.Any(u => u.UserId == x.UserId) && x.ParentId == pid).ToList();
            }
            if (this.State == 100000)
            {
            }
            else
            {
                query = query.Where(x => users.Any(u => u.UserId == x.UserId) && x.State == this.State).ToList();//.ToList(this, x => new ListDistributor(x) { Owner = users.First(u => u.UserId == x.UserId) });
            }
            List = query.ToList(this, x => new ListDistributor(x)
            {
                Owner = users.First(u => u.UserId == x.UserId)
            });
            foreach (var item in List)
            {
                var rate = DistributorService.GetAccountLevelPolicyRates(item.DistributorId).FirstOrDefault();
                if (rate != null)
                {
                    item.Rate = rate.Rate * 100;
                }
            }
            if (query.Count > 0)
            {
                pageHtml = MvcPage.AjaxPager((int)request.PageIndex, (int)request.PageSize, query.Count);
            }
        }
Beispiel #29
0
        public void AddDistributor_Valid()
        {
            //arrange
            IDistributorService service = new DistributorService();
            var distributor             = new Distributor();

            distributor.BODS_FullName = "Agung Pradnya";
            distributor.BODS_Id       = new Guid("617dba9d-391b-4ca7-aeeb-0703ca526709");
            distributor.BODS_Status   = 1;

            //Act
            var actual = service.Add(distributor);

            //Assert
            Assert.AreEqual("Agung Pradnya", actual.BODS_FullName);
        }
Beispiel #30
0
        public void GetAllWithSpecificStatus_ShouldReturnCorrectItems()
        {
            IDistributorService service = new DistributorService();

            var specificStatus = new List <byte> {
                3
            };
            var response = service.GetByStatus(specificStatus);

            Assert.IsTrue(response.Status == StatusFlag.Success);

            // We know from TestDataSource.cs
            var distributor = ((List <Distributor>)response.Data).FirstOrDefault();

            Assert.AreEqual("About Australia", distributor.FullName);
            Assert.AreEqual(Guid.Parse("5df458a8-a743-4e81-bf0d-bd874f6f0cd3"), distributor.Id);
        }
Beispiel #31
0
        public void GetAllWithSpecificId_ShouldReturnCorrectItems()
        {
            IDistributorService service = new DistributorService();

            var specificId = new List <Guid> {
                Guid.Parse("617dba9d-391b-4ca7-aeeb-0703ca526709")
            };
            var response = service.GetById(specificId);

            Assert.IsTrue(response.Status == StatusFlag.Success);

            // We know from TestDataSource.cs
            var distributor = ((List <Distributor>)response.Data).FirstOrDefault();

            Assert.AreEqual("My Website", distributor.FullName);
            Assert.AreEqual(1, distributor.Status);
        }
 public void Initialize()
 {
     _service = new DistributorService(_mockRepository, null);
 }
Beispiel #33
0
 public MockMsmqListener(DistributorService logDistributor, int timerInterval)
     : base(logDistributor, timerInterval)
 {
 }