Exemplo n.º 1
0
        public IQueryable <User> GetById(int?id)
        {
            if (id == null)
            {
                return(null);
            }

            return(context
                   .Set <User>().Where(x => x.UserId == id));
        }
Exemplo n.º 2
0
        public Result <Reward> CreateReward(int rewardPackageId,
                                            CreateRewardOptions options)
        {
            if (options == null)
            {
                return(Result <Reward> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Name))
            {
                return(Result <Reward> .ActionFailed(
                           StatusCode.BadRequest, "Null or empty Name"));
            }

            var rewardPackage = context_
                                .Set <RewardPackage>()
                                .Include(x => x.Rewards)
                                .Where(rp => rp.RewardPackageId == rewardPackageId)
                                .SingleOrDefault();

            if (rewardPackage == null)
            {
                return(Result <Reward> .ActionFailed(
                           StatusCode.BadRequest, "Invalid Reward Package"));
            }

            var reward = new Reward()
            {
                Name = options.Name
            };

            rewardPackage.Rewards.Add(reward);

            var rows = 0;

            try
            {
                rows = context_.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Result <Reward> .ActionFailed(
                           StatusCode.InternalServerError, ex.ToString()));
            }

            if (rows <= 0)
            {
                return(Result <Reward> .ActionFailed(
                           StatusCode.InternalServerError,
                           "Reward could not be created"));
            }

            return(Result <Reward> .ActionSuccessful(reward));
        }
Exemplo n.º 3
0
        public Result <Video> CreateVideo(int projectId,
                                          CreateVideoOptions options)
        {
            if (options == null)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Url))
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.BadRequest, "Null or empty Url"));
            }

            var project = context_
                          .Set <Project>()
                          .Where(p => p.ProjectId == projectId)
                          .SingleOrDefault();

            if (project == null)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.BadRequest, "Invalid projectId"));
            }

            var video = new Video()
            {
                Url = options.Url,
            };

            project.Videos.Add(video);

            var rows = 0;

            try
            {
                rows = context_.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.InternalServerError, ex.ToString()));
            }

            if (rows <= 0)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.InternalServerError,
                           "Video could not be added"));
            }

            return(Result <Video> .ActionSuccessful(video));
        }
Exemplo n.º 4
0
        public Result <Posts> CreatePost(int projectId,
                                         CreatePostOptions options)
        {
            if (options == null)
            {
                return(Result <Posts> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Post))
            {
                return(Result <Posts> .ActionFailed(
                           StatusCode.BadRequest, "Null or empty Post"));
            }

            var project = context_
                          .Set <Project>()
                          .Where(p => p.ProjectId == projectId)
                          .SingleOrDefault();

            if (project == null)
            {
                return(Result <Posts> .ActionFailed(
                           StatusCode.BadRequest, "Invalid projectId"));
            }

            var post = new Posts()
            {
                Post = options.Post
            };

            project.Posts.Add(post);

            var rows = 0;

            try
            {
                rows = context_.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Result <Posts> .ActionFailed(
                           StatusCode.InternalServerError, ex.ToString()));
            }

            if (rows <= 0)
            {
                return(Result <Posts> .ActionFailed(
                           StatusCode.InternalServerError,
                           "Post could not be created"));
            }

            return(Result <Posts> .ActionSuccessful(post));
        }
Exemplo n.º 5
0
        public IQueryable <Project> SearchProject(SearchProjectOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var query = context_
                        .Set <Project>()
                        .AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                query = query.Where(p => p.Name.Contains(options.Name));
            }

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                query = query.Where(p => p.Description == options.Description);
            }

            if (options.ProjectId != null)
            {
                query = query.Where(p => p.ProjectId == options.ProjectId.Value);
            }

            if (options.Category != null && options.Category != 0)
            {
                query = query.Where(p => p.Category == options.Category);
            }

            query = query.Include(p => p.Photos)
                    .Include(p => p.Videos)
                    .Include(p => p.Posts)
                    .Include(p => p.RewardPackages)
                    .ThenInclude(p => p.Rewards)
                    .Include(p => p.User);

            return(query);
        }
Exemplo n.º 6
0
        public Result <RewardPackage> CreateRewardPackage(
            CreateRewardPackageOptions options)
        {
            if (options == null)
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Description))
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Name))
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (options.Amount == null || options.Amount <= 0)
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.BadRequest, "Invalid Amount"));
            }

            var project = context_
                          .Set <Project>()
                          .Where(p => p.ProjectId == options.ProjectId)
                          .SingleOrDefault();

            if (project == null)
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.BadRequest, "Invalid ProjectId"));
            }

            var rewardPackage = new RewardPackage()
            {
                Amount      = options.Amount,
                Description = options.Description,
                Name        = options.Name
            };

            foreach (var option in options.RewardOptions)
            {
                if (option == null)
                {
                    continue;
                }

                var createdReward = rewardService_.AddRewardToList(option);

                if (createdReward != null)
                {
                    rewardPackage.Rewards.Add(createdReward.Data);
                }
                else
                {
                    return(Result <RewardPackage> .ActionFailed(
                               StatusCode.BadRequest, "Invalid Rewards given"));
                }
            }

            project.RewardPackages.Add(rewardPackage);
            context_.Add(rewardPackage);

            var rows = 0;

            try
            {
                rows = context_.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.InternalServerError, ex.ToString()));
            }

            if (rows <= 0)
            {
                return(Result <RewardPackage> .ActionFailed(
                           StatusCode.InternalServerError,
                           "Reward Package could not be created"));
            }

            return(Result <RewardPackage> .ActionSuccessful(rewardPackage));
        }