public async Task <ActionResult <bool> > DeleteOrganisation(OrganisationDelete organisationDelete)
        {
            var org = await _context.Organisations.FirstOrDefaultAsync(x => x.ID == organisationDelete.ID);

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

            if (org.Password != organisationDelete.Password)
            {
                return(false);
            }

            try
            {
                if (org.ImagePath != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(org.ImagePath);
                }

                _context.Organisations.Remove(org);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
        public async Task <ActionResult <bool> > DeleteSolution(int id)
        {
            try
            {
                var solution = await _context.PostSolutions.FindAsync(id);

                //deleting old photo
                if (solution.ImagePath != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(solution.ImagePath);
                }

                _context.PostSolutions.Remove(solution);

                var notify = _context.Notifications.FirstOrDefault(x => x.NewThingID == id && x.TypeOfNotification == 4);
                if (notify != null)
                {
                    _context.Notifications.Remove(notify);
                }

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #3
0
        public async Task <ActionResult <string> > DeleteComment(int id)
        {
            try
            {
                var comment = await _context.Comments.FindAsync(id);

                if (comment.CommentPhoto != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(comment.CommentPhoto);
                }

                _context.Comments.Remove(comment);

                var notify = _context.Notifications.FirstOrDefault(x => x.NewThingID == id && x.TypeOfNotification == 3);
                if (notify != null)
                {
                    _context.Notifications.Remove(notify);
                }


                await _context.SaveChangesAsync();

                return("Comment deleted");
            }
            catch (Exception)
            {
                return("Failed to delete comment with that ID");
            }
        }
Example #4
0
        public async Task <ActionResult <string> > DeletePost(int id)
        {
            try
            {
                var post = await _context.Posts.FirstOrDefaultAsync(x => x.ID == id);

                if (post.PostImage != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(post.PostImage);
                }

                _context.Posts.Remove(post);

                var notify = _context.Notifications.Where(x => x.NotificationForID == id);
                foreach (var item in notify)
                {
                    _context.Notifications.Remove(item);
                }

                await _context.SaveChangesAsync();

                return("Post deleted");
            }
            catch (Exception e)
            {
                return("Failed to delete post with that id");
            }
        }
Example #5
0
        public async Task <ActionResult <bool> > DeleteUser(int id)
        {
            var user = await _context.UserDatas.FirstOrDefaultAsync(x => x.ID == id);

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

            try
            {
                if (user.Photo != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(user.Photo);
                }
                _context.UserDatas.Remove(user);

                var solForDelete = _context.PostSolutions.Where(x => x.UserType == 1 && x.UserID == user.ID);
                foreach (var item in solForDelete)
                {
                    _context.PostSolutions.Remove(item);
                }
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Example #6
0
        public async Task <ActionResult <bool> > DeleteOrganisation(int id)
        {
            var org = await _context.Organisations.FirstOrDefaultAsync(x => x.ID == id);

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

            try
            {
                if (org.ImagePath != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(org.ImagePath);
                }

                _context.Organisations.Remove(org);
                var solForDelete = _context.PostSolutions.Where(x => x.UserType == 2 && x.UserID == org.ID);
                foreach (var item in solForDelete)
                {
                    _context.PostSolutions.Remove(item);
                }
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #7
0
        public async Task <bool> ChangeUserProfileImg(ChangeUserProfileImg changeUserProfileImg)
        {
            try
            {
                var user = await _context.UserDatas.FirstOrDefaultAsync(x => x.ID == changeUserProfileImg.id);


                if (user.Photo != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(user.Photo);
                }


                user.Photo = changeUserProfileImg.photo;



                _context.UserDatas.Update(user);

                _context.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Example #8
0
        public async Task <ActionResult <bool> > EditPost(ChangePost changePost)
        {
            var post = await _context.Posts.FirstOrDefaultAsync(x => x.ID == changePost.ID);

            if (post == null)
            {
                return(false);
            }
            else
            {
                try
                {
                    if (post.PostImage != null && changePost.imageURL != null && changePost.imageURL != post.PostImage)
                    {
                        ImageDelete imgDelete = new ImageDelete();
                        imgDelete.ImageDeleteURL(post.PostImage);
                    }
                    if (changePost.imageURL != null)
                    {
                        post.PostImage = changePost.imageURL;
                    }

                    if (changePost.Title != null)
                    {
                        post.Title = changePost.Title;
                    }

                    if (changePost.Description != null)
                    {
                        post.Description = changePost.Description;
                    }


                    _context.Posts.Update(post);

                    _context.SaveChanges();

                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Example #9
0
        public async Task <ActionResult <string> > DeleteRank(int id)
        {
            try
            {
                var rank = await _context.Ranks.FindAsync(id);

                if (rank.UrlPath != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(rank.UrlPath);
                }

                _context.Ranks.Remove(rank);
                await _context.SaveChangesAsync();

                return("Rank deleted");
            }
            catch (Exception)
            {
                return("Failed to delete rank with that id");
            }
        }
Example #10
0
        public async Task <bool> ChangeOrgData(Organisation org)
        {
            try
            {
                var orgToChange = await _context.Organisations.FirstOrDefaultAsync(x => x.ID == org.ID);

                if (org.Name != null)
                {
                    orgToChange.Name = org.Name;
                }
                if (org.Location != null)
                {
                    orgToChange.Location = org.Location;
                }
                if (org.Email != null)
                {
                    orgToChange.Email = org.Email;
                }
                if (org.ImagePath != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(orgToChange.ImagePath);
                    orgToChange.ImagePath = org.ImagePath;
                }


                _context.Organisations.Update(orgToChange);

                _context.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <ActionResult <bool> > EditOrganisationPost(OrganisationPost OrgPost)
        {
            var orgPostsEdit = await _context.OrganisationPosts.FirstOrDefaultAsync(x => x.ID == OrgPost.ID);

            if (orgPostsEdit == null)
            {
                return(false);
            }
            else
            {
                try
                {
                    if (orgPostsEdit.ImagePath != null)
                    {
                        ImageDelete imgDelete = new ImageDelete();
                        imgDelete.ImageDeleteURL(orgPostsEdit.ImagePath);
                    }

                    orgPostsEdit.Text           = OrgPost.Text;
                    orgPostsEdit.ImagePath      = OrgPost.ImagePath;
                    orgPostsEdit.Time           = OrgPost.Time;
                    orgPostsEdit.OrganisationID = OrgPost.OrganisationID;


                    _context.OrganisationPosts.Update(orgPostsEdit);

                    _context.SaveChanges();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
        public async Task <ActionResult <string> > DeleteOrganisationPost(int id)
        {
            try
            {
                var OrganisationPosts = await _context.OrganisationPosts.FindAsync(id);

                if (OrganisationPosts.ImagePath != null)
                {
                    ImageDelete imgDelete = new ImageDelete();
                    imgDelete.ImageDeleteURL(OrganisationPosts.ImagePath);
                }



                _context.OrganisationPosts.Remove(OrganisationPosts);
                await _context.SaveChangesAsync();

                return("Rank deleted");
            }
            catch (Exception)
            {
                return("Failed to delete rank with that id");
            }
        }
Example #13
0
        public async Task <ActionResult <bool> > EditRank(Rank rank)
        {
            var rankForEdit = await _context.Ranks.FirstOrDefaultAsync(x => x.ID == rank.ID);

            if (rankForEdit == null)
            {
                return(false);
            }
            else
            {
                try
                {
                    rankForEdit.MinPoints = rank.MinPoints;
                    rankForEdit.MaxPoints = rank.MaxPoints;
                    rankForEdit.Name      = rank.Name;

                    if (rankForEdit.UrlPath != null)
                    {
                        ImageDelete imgDelete = new ImageDelete();
                        imgDelete.ImageDeleteURL(rankForEdit.UrlPath);
                    }
                    rankForEdit.UrlPath = rank.UrlPath;


                    _context.Ranks.Update(rankForEdit);

                    _context.SaveChanges();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }