コード例 #1
0
        public void Query()
        {
            if (string.IsNullOrWhiteSpace(this.AccountName))
            {
                var query = PointGiftService.Query().Where(x => x.State == PointGiftStates.Normal);


                List         = BuildQuery(query).ToList(this, x => x);
                CurrentPoint = 0;
            }
            else
            {
                var account = AccountService.GetByName(AccountName);
                if (account != null)
                {
                    AccountUser owner = null;
                    if (account.OwnerId.HasValue)
                    {
                        owner = (AccountUser)MembershipService.GetUserById(account.OwnerId.Value);
                    }
                    CurrentPoint = account.Point;
                    var accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId);

                    var query = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now));

                    List = BuildQuery(query).ToList(this, x => x);
                }
                else
                {
                    ErrorMessage = Localize("nofoundAccount", string.Format("ÕÊ»§ {0} δÕÒµ½", AccountName));
                    List         = new PageOfList <PointGift>(this.OrderBy, this.PageSize);
                }
            }
        }
コード例 #2
0
ファイル: EditPointGift.cs プロジェクト: a864610877/src
        public void Read(int id)
        {
            var pointGift = PointGiftService.GetById(id);

            Photo = new Picture("~/content/pointgiftphotos/{0}", pointGift.Photo, 100, 100);
            this.SetInnerObject(pointGift);
        }
コード例 #3
0
ファイル: CreatePointGift.cs プロジェクト: a864610877/src
        public IMessageProvider Create()
        {
            var serialNo = SerialNoHelper.Create();

            InnerObject.State = PointGiftStates.Normal;
            HttpContext context = HttpContext.Current;

            if (Photo != null && Photo.File != null)
            {
                var name = Guid.NewGuid().ToString("N") + ".jpg";
                InnerObject.Photo = name;
                var fileName = context.Server.MapPath("~/content/pointgiftphotos/" + name);
                Moonlit.IO.DirectoryEnsure.EnsureFromFile(fileName);
                Photo.File.SaveAs(fileName);
            }

            TransactionHelper.BeginTransaction();
            base.OnSave(InnerObject);
            PointGiftService.Create(InnerObject);

            AddMessage("success", DisplayName);
            Logger.LogWithSerialNo(LogTypes.PointGiftCreate, serialNo, InnerObject.PointGiftId, DisplayName);

            return(TransactionHelper.CommitAndReturn(this));
        }
コード例 #4
0
ファイル: ListPointGifts.cs プロジェクト: a864610877/src
        public void Delete(int id)
        {
            var item = this.PointGiftService.GetById(id);

            if (item != null)
            {
                PointGiftService.Delete(item);

                Logger.LogWithSerialNo(LogTypes.PointGiftDelete, SerialNoHelper.Create(), id, item.DisplayName);
                AddMessage("delete.success", item.DisplayName);
            }
        }
コード例 #5
0
ファイル: ListPointGifts.cs プロジェクト: a864610877/src
        public void Resume(int id)
        {
            var item = this.PointGiftService.GetById(id);

            if (item != null && item.State == PointGiftStates.Invalid)
            {
                item.State = PointGiftStates.Normal;
                PointGiftService.Update(item);

                Logger.LogWithSerialNo(LogTypes.PointGiftResume, SerialNoHelper.Create(), id, item.DisplayName);
                AddMessage("resume.success", item.DisplayName);
            }
        }
コード例 #6
0
ファイル: ListPointGifts.cs プロジェクト: a864610877/src
        public void Query()
        {
            var query = PointGiftService.Query();

            if (State != States.All)
            {
                query = query.Where(x => x.State == State);
            }
            if (AccountLevel != Globals.All)
            {
                query = query.Where(x => x.IncludeLevel(AccountLevel));
            }
            this.List = query.ToList(this, x => new ListPointGift(x));
        }
コード例 #7
0
ファイル: EditPointGift.cs プロジェクト: a864610877/src
        public void Save()
        {
            var serialNo = SerialNoHelper.Create();
            var item     = PointGiftService.GetById(PointGiftId);

            if (item != null)
            {
                TransactionHelper.BeginTransaction();
                item.DisplayName = DisplayName;
                item.Point       = Point;
                HttpContext contxt      = HttpContext.Current;
                string      oldFileName = "";
                if (Photo != null && Photo.File != null)
                {
                    var name = Guid.NewGuid().ToString("N") + ".jpg";
                    oldFileName = item.Photo;
                    item.Photo  = name;
                    var fileName = contxt.Server.MapPath("~/content/pointgiftphotos/" + name);
                    Moonlit.IO.DirectoryEnsure.EnsureFromFile(fileName);
                    Photo.File.SaveAs(fileName);
                }

                item.Description = Description;
                item.Category    = Category;
                OnSave(item);
                PointGiftService.Update(item);


                AddMessage("success", DisplayName);
                Logger.LogWithSerialNo(LogTypes.PointGiftEdit, serialNo, item.PointGiftId, DisplayName);


                if (!string.IsNullOrWhiteSpace(oldFileName))
                {
                    try
                    {
                        File.Delete(contxt.Server.MapPath("~/content/pointgiftphotos/" + oldFileName));
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(LogTypes.PointGiftEdit, ex);
                    }
                }
                TransactionHelper.Commit();
            }
        }
コード例 #8
0
ファイル: DoGiftAccount.cs プロジェクト: a864610877/src
        public object Save()
        {
            var serialNo = SerialNoHelper.Create();

            try
            {
                var account = AccountService.GetByName(AccountName);
                if (account == null || account.State != AccountStates.Normal)
                {
                    return(new DataAjaxResult(string.Format(Localize("NoAccount", "会员卡号 {0} 未找到"), AccountName)));
                }
                var passwordService = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);
                var password        = passwordService.Decrypto(Password);
                var accountLevel    = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId);

                var owner = (AccountUser)(account.OwnerId.HasValue ? MembershipService.GetUserById(account.OwnerId.Value) : null);
                var gift  = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now)).FirstOrDefault(x => x.PointGiftId == GiftId);
                if (gift == null)
                {
                    return(new DataAjaxResult(Localize("NoGift", "礼品未找到")));
                }

                if (gift.Point > account.Point)
                {
                    return(new DataAjaxResult(Localize("NoEnoughPoint", "积分不足")));
                }
                if (User.SaltAndHash(password, account.PasswordSalt) != account.Password)
                {
                    return(new DataAjaxResult(Localize("error.Password", "密码错误")));
                }

                account.Point -= gift.Point;
                TransactionHelper.BeginTransaction();
                AccountService.Update(account);
                DealLogService.Create(new DealLog(serialNo, DealTypes.Gift, 0, -gift.Point, null, null, account, null, gift.PointGiftId));

                Logger.LogWithSerialNo(LogTypes.AccountDoGift, serialNo, account.AccountId, account.Name, gift.DisplayName);
                return(TransactionHelper.CommitAndReturn(new DataAjaxResult()));
            }
            catch (System.Exception ex)
            {
                Logger.Error(LogTypes.AccountDoGift, ex);

                return(new DataAjaxResult(Localize("Error", "兑换失败")));
            }
        }