コード例 #1
0
ファイル: UserPointLogic.cs プロジェクト: rickaka01/QA
        public bool CreatePoint(Guid userId, int p)
        {
            var model = new UserPointModel {
                UserID = userId, Point = p
            };

            return(udb.Create(model));
        }
コード例 #2
0
        public IActionResult SaveUserPoint(UserPointModel userPointModel)
        {
            var id        = userPointModel.Id;
            var userPoint = id > 0 ? _userPointService.Get(id) : new UserPoint()
            {
                ActivatorUserId = CurrentUser.Id,
                CreatedOn       = DateTime.UtcNow,
                UserId          = userPointModel.UserId
            };


            if (userPoint == null)
            {
                return(NotFound());
            }
            userPoint.Points = userPointModel.Points;
            userPoint.Reason = userPointModel.Reason;
            _userPointService.InsertOrUpdate(userPoint);
            return(R.Success.Result);
        }
コード例 #3
0
        public Operation <UserPointModel> AddOrUpdateUserPoint(UserPointModel model)
        {
            return(Operation.Create(() =>
            {
                if (model == null)
                {
                    _logger.LogError("User point cannot be empty");
                    throw new Exception("User point cannot be empty");
                }

                bool validate = model.Validate();
                if (!validate)
                {
                    _logger.LogError("User point name cannot be empty");
                    throw new Exception("User point name cannot be empty");
                }

                var query = _repo.UserPoint.Include(c => c.User).FirstOrDefault(c => c.UserPointId == model.UserPointId);

                if (query == null)
                {
                    query = _mapper.Map <UserPointModel, UserPoint>(model);
                    _repo.Add <UserPoint>(query);
                    _repo.SaveChanges();
                }
                else
                {
                    query.Channel = model.Channel;
                    query.UserId = model.UserId;
                    query.Point = model.Point;

                    query.ModifiedBy = model.ModifiedBy.HasValue ? model.ModifiedBy.Value : 0;
                    query.ModifiedDate = DateTime.Now;

                    _repo.Update <UserPoint>(query);
                    _repo.SaveChanges();
                }

                return _mapper.Map <UserPoint, UserPointModel>(query);
            }));
        }
コード例 #4
0
        public IActionResult Post([FromBody] UserPointModel model)
        {
            try
            {
                model.CreatedBy  = UserId;
                model.ModifiedBy = UserId;

                var post = _service.AddOrUpdateUserPoint(model);

                if (post.Succeeded)
                {
                    return(Ok(post));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save  user point:{ex}");
            }

            return(BadRequest("Failed to save user point"));
        }
コード例 #5
0
        public Operation <UserPointModel> AddUserPointOrUpdate(UserPointModel model)
        {
            return(Operation.Create(() =>
            {
                if (model == null)
                {
                    _logger.LogError("UserPoint cannot be empty");
                    throw new Exception("UserPoint cannot be empty");
                }

                bool validate = model.Validate();
                if (!validate)
                {
                    _logger.LogError("UserPoint ref cannot be empty");
                    throw new Exception("UserPoint ref cannot be empty");
                }

                var query = _repo.UserPoint.FirstOrDefault(c => c.UserPointId == model.UserPointId);

                if (query == null)
                {
                    query = _mapper.Map <UserPointModel, UserPoint>(model);
                    query.ReceiptId = model.ReceiptId;
                    query.QuestionId = model.QuestionId;
                    query.ProductId = model.ProductId;
                    query.VideoId = model.VideoId;

                    _repo.Add <UserPoint>(query);
                    _repo.SaveChanges();
                }
                else
                {
                    //query = _mapper.Map<VideoModel, Video>(model);

                    query.UserId = model.UserId;
                    query.Channel = model.Channel;
                    query.ModifiedBy = model.ModifiedBy.HasValue ? model.ModifiedBy.Value : 0;
                    query.ModifiedDate = DateTime.Now;
                    query.Point = model.Point;

                    query.ReceiptId = model.ReceiptId;
                    query.QuestionId = model.QuestionId;
                    query.ProductId = model.ProductId;
                    query.VideoId = model.VideoId;

                    _repo.Update <UserPoint>(query);
                    _repo.SaveChanges();
                }

                return new UserPointModel()
                {
                    Channel = query.Channel,
                    IsCancelled = query.IsCancelled,
                    Point = query.Point,
                    UserId = query.UserId,
                    UserPointId = query.UserPointId,
                    Status = query.Status,
                    CreatedBy = query.CreatedBy
                };
            }));
        }