Exemplo n.º 1
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);
            }));
        }
Exemplo n.º 2
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
                };
            }));
        }