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 IActionResult Delete(int id) { try { _distributorService.Delete(id); TempData["Info"] = "Dystrybutor został usunięty"; } catch (Exception) { TempData["Warning"] = "Wystapił błąd podczas usuwania dystrybutora."; throw; } return(RedirectToAction("Index", "Distributor")); }