public void IfFileToCopyDoesNotExistReturnError()
        {
            var model = new ViewImageModel(copyLocation);

            model.CopyImage("~\\InvalidPath\\image.png");
            Assert.IsFalse(String.IsNullOrEmpty(model.Error));
        }
        public void IfCopyDirectoryDoesNotExistReturnsError()
        {
            var model = new ViewImageModel("~\\InvalidLocation\\");

            model.CopyImage("~\\InvalidPath\\image.png");
            Assert.IsFalse(String.IsNullOrEmpty(model.Error));
        }
Esempio n. 3
0
        public ActionResult EditImage(int id)
        {
            ViewBag.User = userService.GetUserByEmail(User.Identity.Name);
            ViewImageModel image = Mapper.Map <ImageDTO, ViewImageModel>(imageService.GetById(id));

            return(View(image));
        }
Esempio n. 4
0
        public ActionResult ViewImage(string filepath, string id)
        {
            var model = new ViewImageModel(MASTER_IMAGE_LOCATION);

            model.CopyImage(filepath, id);
            if (String.IsNullOrEmpty(model.Error))
            {
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(Json(model.FilePath));
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(model.Error));
        }
        public void IfFileNameSetCopiedImageWillBeRenamedToFileName()
        {
            var filePath    = "..\\..\\..\\..\\..\\..\\test\\TestImages\\752.jpg";
            var model       = new ViewImageModel(copyLocation);
            var newFileName = "renamedFile";

            model.CopyImage(filePath, newFileName);
            Assert.AreEqual(copyLocation + newFileName + Path.GetExtension(filePath), model.FilePath);

            Assert.AreEqual(newFileName + Path.GetExtension(filePath), Path.GetFileName(model.ImagePath));
            Assert.IsTrue(File.Exists(model.FilePath));
            // cleanup
            model.DeleteImage(model.FilePath);
            Assert.IsFalse(File.Exists(model.FilePath));
        }
        public void IfFileCopiedThenFilePathSetToNewFile()
        {
            var filePath = "..\\..\\..\\..\\..\\..\\test\\TestImages\\752.jpg";
            var model    = new ViewImageModel(copyLocation);

            model.CopyImage(filePath);
            Assert.AreEqual(copyLocation + Path.GetFileName(filePath), model.FilePath);

            Assert.IsTrue(File.Exists(model.FilePath));
            // cleanup
            model.DeleteImage(model.FilePath);
            Assert.IsFalse(File.Exists(model.FilePath));

            // call method which deletes the file that has been created
        }
        public ActionResult ViewImage(int id)
        {
            var repo = new ImageRepository(Properties.Settings.Default.ConStr);
            var VIM  = new ViewImageModel {
                Image = repo.GetImagebyId(id)
            };

            if (HasPermission(id))
            {
                VIM.HasPermission = true;
            }
            else
            {
                VIM.HasPermission = false;
            }
            return(View(VIM));
        }
        // GET: ViewImage
        public ActionResult Index(String fileId)
        {
            var man      = new ImageManager();
            var ii       = man.RetrieveByGuid(Guid.Parse(fileId));
            var model    = new ViewImageModel();
            var tagNames = new List <String>();

            foreach (var t in ii.Tags)
            {
                tagNames.Add(t.TagName);
            }

            model.FileGuid    = ii.ImageGuid;
            model.Tags        = String.Join(" , ", tagNames);
            model.FileName    = ii.ImageName;
            model.Description = ii.Description;

            return(View(model));
        }
Esempio n. 9
0
        public ActionResult ImportMaster(string id, string fileId, string filePath)
        {
            // copy master image to root directory to allow it display
            // set the name of the local master image to the project id
            var image = new ViewImageModel(MASTER_IMAGE_LOCATION);

            image.CopyImage(filePath, id);

            // update project status and store master file id
            var model    = new MasterFileModel();
            var response = model.InsertMasterFile(client, id, fileId, image.ImagePath);

            if (String.IsNullOrEmpty(response.Error))
            {
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(Json("The update large file id request was valid"));
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(response.Error));
        }
        public ActionResult ViewImage(int id)
        {
            ImageManager   mgr = new ImageManager(Properties.Settings.Default.ConStr);
            ViewImageModel vm  = new ViewImageModel();

            vm.Message = (string)TempData["Message"];
            vm.image   = mgr.GetImageById(id);

            if (Session["AllowedId"] != null)
            {
                List <int> AllowedId = (List <int>)Session["AllowedId"];
                if (AllowedId.Contains(id))
                {
                    vm.HasPermission = true;
                    mgr.UpdateView(id);
                }
            }


            return(View(vm));
        }
        public ActionResult PreviewEdges(string id, int threshold)
        {
            var model    = new GenerateMosaicModel();
            var response = model.PreviewEdges(client, id, threshold);

            if (String.IsNullOrEmpty(response.Error))
            {
                // copy generated image to root directory to allow it display
                var image = new ViewImageModel(EDGE_IMAGE_LOCATION);
                image.CopyImage(response.Location);
                // update project status and store location
                var insertResponse = new EdgeFileModel().InsertEdgeFile(client, id, image.ImagePath);
                if (String.IsNullOrEmpty(insertResponse.Error))
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Json(image.ImagePath));
                }
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(response.Error));
        }
        public ActionResult GenerateMosaic(string id, bool random, int tileWidth, int tileHeight, bool colourBlended, bool enhanced, int enhancedThreshold, bool edgeDetection, int edgeDetectionThreshold)
        {
            // Generate the mosaic passing the project id and whether to randomise tile selection
            var model    = new GenerateMosaicModel();
            var response = model.Generate(client, id, random, tileWidth, tileHeight, colourBlended, enhanced, enhancedThreshold, edgeDetection, edgeDetectionThreshold);

            if (String.IsNullOrEmpty(response.Error))
            {
                // copy generated image to root directory to allow it display
                var image = new ViewImageModel();
                image.CopyImage(response.Location);
                // update project status and store location
                var insertResponse = new MosaicFileModel().InsertMosaicFile(client, id, image.ImagePath);
                if (String.IsNullOrEmpty(insertResponse.Error))
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Json(image.ImagePath));
                }
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(response.Error));
        }
Esempio n. 13
0
        public ActionResult EditImage(HttpPostedFileBase uploadImage, ViewImageModel model)
        {
            ViewBag.User = userService.GetUserByEmail(User.Identity.Name);
            int flag = 0;

            foreach (var item in imageService.GetAll())
            {
                if (item.Name.Equals(model.Name))
                {
                    flag++;
                    break;
                }
            }
            if (flag > 0 && model.Id == 0)
            {
                ModelState.AddModelError("", "Такое наименование уже существует");
            }

            if (ModelState.IsValid)
            {
                if (uploadImage != null && model.Id == 0)
                {
                    byte[] imageData = null;
                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }
                    imageService.Create(new ImageDTO {
                        Id = model.Id, Data = imageData, Name = model.Name
                    });
                    TempData["message"] = string.Format("Добавление изображения выполнено успешно");

                    if (userService.GetUserByEmail(User.Identity.Name).RoleId == 2)
                    {
                        return(RedirectToAction("TeacherPanel", "Teacher", new { result = "images" }));
                    }
                    return(RedirectToAction("AdminPanel", new { result = "images" }));
                }
                if (model.Id != 0)
                {
                    if (uploadImage != null)
                    {
                        byte[] imageData = null;
                        using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                        {
                            imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                        }
                        imageService.Update(new ImageDTO {
                            Id = model.Id, Data = imageData, Name = model.Name
                        });
                        if (userService.GetUserByEmail(User.Identity.Name).RoleId == 2)
                        {
                            return(RedirectToAction("TeacherPanel", "Teacher", new { result = "images" }));
                        }
                        return(RedirectToAction("AdminPanel", new { result = "images" }));
                    }
                    else
                    {
                        imageService.Update(new ImageDTO {
                            Id = model.Id, Data = imageService.GetById(model.Id).Data, Name = model.Name
                        });
                        if (userService.GetUserByEmail(User.Identity.Name).RoleId == 2)
                        {
                            return(RedirectToAction("TeacherPanel", "Teacher", new { result = "images" }));
                        }
                        return(RedirectToAction("AdminPanel", new { result = "images" }));
                    }
                }
            }

            return(View());
        }