示例#1
0
        public static async Task <int> RemoveImageAsync(Data data)
        {
            ProjectController projectController = new ProjectController();
            ImageController   imageController   = new ImageController();
            Project           project           = await projectController.GetAsync(data.ProjectId);

            string img_path = $"./Ressources/Images/{project.Id}_{project.Name}/{data.Name}";

            imageController.DeleteAsync(data.Id);
            System.IO.File.Delete(img_path);
            return(200);
        }
        public async Task <Model> GetAsync(int id)
        {
            ImageController imageController = new ImageController();
            Project         project         = await GetModelByIdAsync(id);

            List <Image> images        = (await imageController.GetByProjectId(project.Id)).ToList();
            List <Data>  projectImages = new List <Data>();

            foreach (var item in images)
            {
                projectImages.Add(await imageController.GetAsyncPicture(item.Id));
            }
            if (!project.LabeledPath.IsNullOrEmpty())
            {
                project.LabeledPath = System.IO.File.ReadAllText(project.LabeledPath);
            }
            project.Images = projectImages;
            return(project);
        }
示例#3
0
        public static async Task <Image> ImageUploadAsync(Data data)
        {
            try
            {
                ProjectController projectController = new ProjectController();
                ImageController   imageController   = new ImageController();
                data = GetBase64OutOfXML(data);
                var     bytes   = data.Base64.Base64ToByte();
                Project project = await projectController.GetAsyncOnlyProject(data.ProjectId);

                Image image = new Image();

                //Queries whether the directory (for images) of the respective project exists and creates it if not.
                string dir_path = $"./Ressources/Images/{project.Id}_{project.Name}";
                if (!System.IO.Directory.Exists(dir_path))
                {
                    System.IO.Directory.CreateDirectory(dir_path);
                }

                //Queries whether the image exists
                //  -if so, it will only be updated
                //  -if no, a database entry is made with the respective path
                string img_path = $"./Ressources/Images/{project.Id}_{project.Name}/{data.Name}";
                if (!System.IO.File.Exists(img_path))
                {
                    image.ImagePath = img_path;
                    image.ProjectId = data.ProjectId;
                }

                //the image is saved
                await System.IO.File.WriteAllBytesAsync(img_path, bytes);

                await imageController.SetImage(image);

                return(image);
            }
            catch (Exception er)
            {
                Console.WriteLine(er.ToString());
                return(null);
            }
        }