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); }
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 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); }
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 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))); } }
public void Read(int id) { var distributor = DistributorService.GetById(id); if (distributor != null) { var owner = MembershipService.GetUserById(distributor.UserId) as DistributorUser; SetInnerObject(distributor, owner); } }
/// <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(); }
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); }
// GET: TankDistributor/Edit/5 public IActionResult Edit(int tankId, int distributorId) { var tank = _tankDistributorService.GetById(tankId, distributorId); if (tank == null) { return(NotFound()); } TankDistributor model = new TankDistributor { TankId = tankId, DistributorId = distributorId, Tank = _tankService.GetById(tankId), Distributor = _distributorService.GetById(distributorId) }; return(View(model)); }
// GET: Distributor/Edit/5 public IActionResult Edit(int id) { var distributor = _distributorService.GetById(id); if (distributor == null) { return(NotFound()); } Distributor model = new Distributor { DistributorId = distributor.DistributorId, IsLocked = distributor.IsLocked, Counter = distributor.Counter, Fuelings = distributor.Fuelings, TankDistributors = distributor.TankDistributors }; return(View(model)); }
/// <summary> /// 是否是自己的下级 /// </summary> /// <param name="distributorId">下级</param> /// <param name="pid">上级</param> /// <returns></returns> public bool GetTopLevelDistributorId(int distributorId, int pid) { var parent = DistributorService.GetById(distributorId); if (parent != null) { if (parent.ParentId == pid) { return(true); } } if (parent.ParentId == 0) { return(false); } else { return(GetTopLevelDistributorId(parent.ParentId, pid)); } }
/// <summary> /// 根据输入的经销商Id取得一级经销商的Id /// </summary> /// <param name="distributorId"></param> /// <returns></returns> public int GetTopLevelDistributorId(int distributorId) { var parent = DistributorService.GetById(distributorId); if (parent != null) { if (parent.ParentId == 0) { return(parent.DistributorId); } else { return(GetTopLevelDistributorId(parent.ParentId)); } } else { return(0); } }
/// <summary> /// 取得直接下属的Id /// </summary> /// <param name="parentId"></param> /// <param name="Id"></param> /// <returns></returns> public int GetDirectlyUnder(int parentId, int Id) { var item = DistributorService.GetById(Id); if (item != null) { if (item.ParentId == parentId) { return(Id); } else { return(GetDirectlyUnder(parentId, item.ParentId)); } } else { return(0); } }
public void InsertNewRecord_ShouldReturnCorrectItem() { var newItem = new Distributor { FullName = "I Putu Yoga Permana", Status = 1 }; IDistributorService service = new DistributorService(); var response = service.Add(newItem); var guid = (Guid)response.Data; // Get the newly created item var distributorResponse = service.GetById(new List <Guid> { guid }); var distributorCollection = (List <Distributor>)distributorResponse.Data; Assert.AreEqual(distributorCollection.FirstOrDefault().FullName, newItem.FullName); Assert.AreEqual(distributorCollection.FirstOrDefault().Status, newItem.Status); }
public ResultMsg Resume(int id) { ResultMsg msg = new ResultMsg(); try { var item = DistributorService.GetById(id); if (item != null && item.State == DistributorStates.Invalid) { item.State = DistributorStates.Normal; var owner = MembershipService.GetUserById(item.UserId); TransactionHelper.BeginTransaction(); DistributorService.Update(item); owner.State = UserStates.Normal; MembershipService.UpdateUser(owner); Logger.LogWithSerialNo(LogTypes.DistributorResume, SerialNoHelper.Create(), id, owner.Name); // AddMessage("resume.success", owner.Name); msg.Code = 1; msg.CodeText = "启用经销商 " + owner.DisplayName + " 成功"; TransactionHelper.Commit(); CacheService.Refresh(CacheKeys.PosKey); } else { msg.CodeText = "不好意思,没有找到经销商"; } return(msg); } catch (Exception ex) { msg.CodeText = "不好意思,系统异常"; Logger.Error("启用经销商", ex); return(msg); } }
public ResultMsg Suspend(int id) { ResultMsg msg = new ResultMsg(); try { var distributor = DistributorService.GetById(id); if (distributor != null && distributor.State == DistributorStates.Normal) { var user = MembershipService.GetUserById(distributor.UserId) as DistributorUser; TransactionHelper.BeginTransaction(); distributor.State = DistributorStates.Invalid; DistributorService.Update(distributor); user.State = UserStates.Invalid; MembershipService.UpdateUser(user); Logger.LogWithSerialNo(LogTypes.DistributorSuspend, SerialNoHelper.Create(), id, user.Name); // AddMessage("suspend.success", user.Name); msg.Code = 1; msg.CodeText = "停用经销商 " + distributor.DisplayName + " 成功"; TransactionHelper.Commit(); CacheService.Refresh(CacheKeys.PosKey); } else { msg.CodeText = "不好意思,没有找到经销商"; } return(msg); } catch (Exception ex) { msg.CodeText = "不好意思,系统异常"; Logger.Error("停用经销商", ex); return(msg); } }
/// <summary> /// 更改经销商 /// </summary> /// <param name="id"></param> /// <param name="distributorId"></param> public void SetDistributor(int id, int distributorId) { this.TransactionHelper.BeginTransaction(); Account item = AccountService.GetById(id); if (item != null && item.State == States.Normal) { var distributor = DistributorService.GetById(distributorId); if (distributor != null) { item.DistributorId = distributorId; AccountService.Update(item); Logger.LogWithSerialNo(LogTypes.AccountSuspend, SerialNoHelper.Create(), id, item.Name); AddMessage("Update.success", item.Name); } else { AddError("经销商不存在?", distributorId); } } this.TransactionHelper.Commit(); }
public void EditMultipleRecord_ShouldBeUpdated() { var listUpdatedItem = new List <Distributor> { new Distributor { // specific id from TestDataSource.cs Id = Guid.Parse("617dba9d-391b-4ca7-aeeb-0703ca526709"), FullName = "Zombie Killer", Status = 3 }, new Distributor { // specific id from TestDataSource.cs Id = Guid.Parse("bee3c0be-ccbf-4882-ad5a-d288f5677a51"), FullName = "Ninja Master", Status = 2 } }; IDistributorService service = new DistributorService(); var response = service.Update(listUpdatedItem); Assert.IsTrue(response.Status == StatusFlag.Success); // Make sure the data already be updated var updatedItemId = listUpdatedItem.Select(i => i.Id).ToList(); var distResponse = service.GetById(updatedItemId); var distributor = (List <Distributor>)distResponse.Data; for (int i = 0; i < 2; i++) { Assert.AreEqual(listUpdatedItem[i].FullName, distributor[i].FullName); Assert.AreEqual(listUpdatedItem[i].Status, distributor[i].Status); } }
public void Query() { var request = new DistributorBrokerageRequest(); //request.AccountId = this.AccountId; request.SubmitTimeMin = Data.Start; request.SubmitTimeMax = Data.End; request.NameWith = AccountName; if (Distributor != -10001) { request.DistributorId = Distributor; } if (State == 1) { request.Status = true; } if (State == 0) { request.Status = false; } var q = DistributorBrokerageService.QueryBrokerage(request).ToList(); //如果是系统总部,列表中只包含一级经销商。 var distributors = DistributorService.Query().Where(x => x.ParentId == 0).ToList(); var user = this.SecurityHelper.GetCurrentUser(); if (user is AdminUserModel) { List = List = q.ToList(this, x => new ListDistributorBrokerage(x));//(from c in q where distributors.Any(p=>p.DistributorId==c.DistributorId) select c).ToList(this,x=>new ListDistributorBrokerage(x)); } //显示直属当前经销商和归属当前经销商的下级 else if (user is DistributorUserModel) { int id = ((DistributorUserModel)user).DistributorId; var totalIds = q.Select(x => x.DistributorId).ToList(); var ids = GetChildrenDistributorId(id, totalIds); ids.Add(id); List = (from c in q where ids.Contains(c.settlementDistributorId) select c).ToList(this, x => new ListDistributorBrokerage(x)); } foreach (var item in List) { var distributor1 = DistributorService.GetById(item.DistributorId); if (distributor1 != null) { var distributoruser = MembershipService.GetUserById(distributor1.UserId); if (user != null) { item.DistributorName = distributoruser.DisplayName; } } var distributor2 = DistributorService.GetById(item.settlementDistributorId); if (distributor2 != null) { var distributoruser = MembershipService.GetUserById(distributor2.UserId); if (user != null) { item.SettlementDistributorName = distributoruser.DisplayName; } } var account = AccountService.GetById(item.AccountId); if (account != null) { item.AccountName = account.Name; } } }