public bool DeleteProjectWithId(int id)
        {
            Project project = dbContext.Set <Project>().Find(id);

            if (project == null)
            {
                return(false);
            }
            dbContext.Remove(project);
            dbContext.SaveChanges();
            return(true);
        }
        public Result <bool> DeleteProject(int id)
        {
            var result = new Result <bool>();

            if (id <= 0)
            {
                result.ErrorCode = StatusCode.BadRequest;
                result.ErrorText = $"Id {id} is invalid";
                return(result);
            }

            var project = SearchProject(new SearchProjectOptions()
            {
                ProjectId = id
            }).Include(p => p.Packages)
                          .Include(p => p.User)
                          .ThenInclude(u => u.Projects)
                          .SingleOrDefault();

            if (project == null)
            {
                result.ErrorCode = StatusCode.NotFound;
                result.ErrorText = $"Project with id {id} was not found";
                return(result);
            }

            try
            {
                if (project.User.Projects.Count() == 1)
                {
                    project.User.IsProjectCreator = false;
                }

                dbContext.Remove(project);

                if (dbContext.SaveChanges() > 0)
                {
                    result.ErrorCode = StatusCode.OK;
                    result.Data      = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ErrorCode = StatusCode.InternalServerError;
                result.ErrorText = ex.ToString();
                return(result);
            }

            result.ErrorCode = StatusCode.InternalServerError;
            result.ErrorText = $"Customer could not be deleted";
            return(result);
        }
        public bool DeletePackageFromProject(int packageId)
        {
            Package package = dbContext.Set <Package>().Find(packageId);

            if (package == null)
            {
                return(false);
            }
            dbContext.Remove(package);
            dbContext.SaveChanges();
            return(true);
        }
        public bool DeleteUserWithId(int id)
        {
            User user = dbContext.Set <User>().Find(id);

            if (user == null)
            {
                return(false);
            }
            dbContext.Remove(user);
            dbContext.SaveChanges();
            return(true);
        }
Exemple #5
0
        public Result <bool> DeletePackage(int packageId)
        {
            var result = new Result <bool>();

            if (packageId <= 0)
            {
                result.ErrorCode = StatusCode.BadRequest;
                result.ErrorText = $"Id {packageId} is invalid";
                return(result);
            }

            var package = dbContext.Set <Package>()
                          .Where(p => p.PackageId == packageId)
                          .SingleOrDefault();

            if (package == null)
            {
                result.ErrorCode = StatusCode.NotFound;
                result.ErrorText = $"Package with id {packageId} was not found";
                return(result);
            }

            try
            {
                dbContext.Remove(dbContext.Set <Package>()
                                 .Where(p => p.PackageId == packageId)
                                 .SingleOrDefault());

                if (dbContext.SaveChanges() > 0)
                {
                    result.ErrorCode = StatusCode.OK;
                    result.Data      = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ErrorCode = StatusCode.InternalServerError;
                result.ErrorText = ex.ToString();
                return(result);
            }

            result.ErrorCode = StatusCode.InternalServerError;
            result.ErrorText = $"Package could not be deleted";
            return(result);
        }
Exemple #6
0
        public Result <bool> DeleteUser(int id)
        {
            var result = new Result <bool>();

            if (id <= 0)
            {
                result.ErrorCode = StatusCode.BadRequest;
                result.ErrorText = $"Id {id} is invalid";
                return(result);
            }

            var user = GetUserById(id);

            if (user == null)
            {
                result.ErrorCode = StatusCode.NotFound;
                result.ErrorText = $"User with id {id} was not found";
                return(result);
            }

            try
            {
                dbContext.Remove(user);
                if (dbContext.SaveChanges() > 0)
                {
                    result.ErrorCode = StatusCode.OK;
                    result.Data      = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.ErrorCode = StatusCode.InternalServerError;
                result.ErrorText = ex.ToString();
                return(result);
            }

            result.ErrorCode = StatusCode.InternalServerError;
            result.ErrorText = $"User could not be deleted";
            return(result);
        }