Esempio n. 1
0
        public async Task <IActionResult> PointExch(string id)
        {
            if (ModelState.IsValid)
            {
                var memberInfo = await(from m in _applicationDbContext.Members
                                       where m.MemberID.Equals(id, StringComparison.InvariantCultureIgnoreCase)
                                       select m)
                                 .FirstOrDefaultAsync();

                if (memberInfo == null)
                {
                    return(HttpNotFound("MemberID is not Exist."));
                }

                MemberPointInfoViewModel pointInfo = await GetMemberPointInfo(memberInfo.MemberID);

                if (pointInfo == null)
                {
                    pointInfo = new MemberPointInfoViewModel
                    {
                        MemberID    = memberInfo.MemberID,
                        PointTotal  = 0,
                        UsablePoint = 0,
                    };
                }

                pointInfo.IDCard     = memberInfo.IDCard;
                pointInfo.MemberName = memberInfo.Name;

                return(Json(pointInfo));
            }
            return(ErrorMessage.BadRequestJsonResult(ModelState.Values.SelectMany(x => x.Errors)));
        }
Esempio n. 2
0
        public async Task <IActionResult> PointExch(MemberPointInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ExchAmount < 0)
                {
                    return(ErrorMessage.BadRequestJsonResult("ExchAmount must be greater than 0."));
                }

                MemberPointInfoViewModel pointInfo = await GetMemberPointInfo(model.MemberID);

                if (pointInfo == null || pointInfo.UsablePoint < model.ExchAmount)
                {
                    return(ErrorMessage.BadRequestJsonResult("ExchAmount is greater than UsablePoint."));
                }

                MemberPoint exchPoint = new MemberPoint();
                exchPoint.ID            = IDGenerator.GetMemberPointIDGenerator(_applicationDbContext).GetNext();
                exchPoint.OwnerMemberID = model.MemberID;
                exchPoint.Type          = "PointExch";
                exchPoint.OperationBy   = new Member
                {
                    MemberID = (await this.GetCurrentUserAsync()).UserName
                };
                exchPoint.Quantity             = -model.ExchAmount;
                exchPoint.CurrentTotalQuantity = pointInfo.PointTotal;

                this._applicationDbContext.MemberPoint.Add(exchPoint);
                this._applicationDbContext.SaveChanges();


                MemberPointInfoViewModel newPointInfo = await GetMemberPointInfo(model.MemberID);

                newPointInfo.IDCard     = model.IDCard;
                newPointInfo.MemberName = model.MemberName;
                return(Json(newPointInfo));
            }
            return(ErrorMessage.BadRequestJsonResult(ModelState.Values.SelectMany(x => x.Errors)));
        }