Example #1
0
        public async Task <bool> JoinGroup(UsersGroup ug)
        {
            int userId  = ug.UserId;
            int groupId = ug.GroupId;

            //Check if record exists
            UsersGroup usersGroup = await _context.UsersGroups
                                    .Where(x => x.UserId == userId)
                                    .FirstOrDefaultAsync(x => x.GroupId == groupId);


            if (usersGroup == null)
            {
                _context.Add(ug);
                var saveResult = await _context.SaveChangesAsync();

                return(true);
            }
            else
            {
                _context.UsersGroups.Remove(usersGroup);
                var saveResult = await _context.SaveChangesAsync();

                return(false);
            }
        }
Example #2
0
        public async Task <bool> AddGroup(Group group)
        {
            group.UsersGroups = await this.CheckUsernameExist(group.UsersGroups.ToList());

            group.GroupTags = await this.CheckTagsDatabase(group.GroupTags.ToList());

            _context.Add(group);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult >= 1);
        }
        public async Task <bool> AddComment(int recipeId, Comment comment)
        {
            var recipe = await _context.Recipes.FirstOrDefaultAsync(r => r.RecipeId == recipeId);

            if (recipe == null)
            {
                return(false);
            }

            comment.Recipe = recipe;
            _context.Add(comment);
            var success = await _context.SaveChangesAsync();

            return(success >= 1);
        }
Example #4
0
        public async Task <bool> AddRecipe(Recipe recipe)
        {
            ApplicationUser user = await _context.Users.FirstOrDefaultAsync(u => u.Id == recipe.UserId);

            recipe.User       = user;
            recipe.RecipeTags = await this.CheckTagsDatabase(recipe.RecipeTags.ToList());

            recipe.RecipeGroups = await this.CheckGroupDatabase(recipe.RecipeGroups.ToList());

            _context.Add(recipe);

            var saveResult = await _context.SaveChangesAsync();

            return(saveResult >= 1);
        }
        public async Task <IActionResult> UpdateDisbursementDetails([FromBody] List <DisbursementDetailAPIModel> ListofdisbursementdetailsAPIModel)
        {
            try
            {
                for (int i = 0; i < ListofdisbursementdetailsAPIModel.Count; i++)
                {
                    DisbursementDetails disbursementdetails = disbursementapiservice.APImodelconvertoDisbursementDetailmodel(ListofdisbursementdetailsAPIModel[i]);

                    _context.Entry(disbursementdetails).State = EntityState.Modified;
                    //use first disbursementdetails to change disbursementdetailapproval
                    if (i == 0)
                    {
                        disbursementapiservice.ChangeDisbursementStatustocollectbyDisbursementDetail(disbursementdetails);
                    }
                }
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }
        }