public IActionResult Create(DistributorCreate distributorCreate)
 {
     if (ModelState.IsValid)
     {
         _distributorService.Create(distributorCreate);
         TempData["Info"] = "Dytrybutor został dodany";
         return(RedirectToAction(nameof(Index)));
     }
     return(View(distributorCreate));
 }
Esempio n. 2
0
        public IMessageProvider Create()
        {
            var serialNo = SerialNoHelper.Create();
            var roles    = MembershipService.QueryRoles(new RoleRequest {
                Name = RoleNames.DistributorOwner
            }).ToList();

            TransactionHelper.BeginTransaction();
            InnerObject.DistributorLevel = DistributorLevel;
            OnSave(InnerObject, Owner);
            var user = this.SecurityHelper.GetCurrentUser();

            if (user is AdminUserModel)
            {
                InnerObject.ParentId = 0;
            }
            else if (user is DistributorUserModel)
            {
                InnerObject.ParentId = ((DistributorUserModel)user).DistributorId;
            }
            Owner.SetPassword(Password);
            InnerObject.State = States.Normal;//经销商状态

            Owner.State = States.Normal;
            MembershipService.CreateUser(Owner);
            InnerObject.UserId = Owner.UserId;
            DistributorService.Create(InnerObject);
            UpdateAccountLevelPolicy(InnerObject);
            MembershipService.AssignRoles(Owner, roles.Select(x => x.RoleId).ToArray());
            DistributorDealLog log = new DistributorDealLog(serialNo, DealTypes.Open, 0, null, null, null, InnerObject, 0);

            //DistributorDealLogService.Create(log);
            AddMessage("success", this.UserName);
            Logger.LogWithSerialNo(LogTypes.DistributorCreate, serialNo, InnerObject.DistributorId, this.UserName);
            CacheService.Refresh(CacheKeys.PosKey);
            return(TransactionHelper.CommitAndReturn(this));
        }