Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public void Read(int id)
        {
            var pointGift = PointGiftService.GetById(id);

            Photo = new Picture("~/content/pointgiftphotos/{0}", pointGift.Photo, 100, 100);
            this.SetInnerObject(pointGift);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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();
            }
        }
Ejemplo n.º 8
0
        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", "兑换失败")));
            }
        }