Exemplo n.º 1
0
        public void Post([FromBody] CreateImageCommand request)
        {
            var repository = new ImagesRepository();

            var tagRepository = new TagsRepository();

            var tags = new List <ImorTag>();

            foreach (var tag in request.Tags)
            {
                var existingTag = tagRepository.GetTagByUri(tag);

                if (existingTag != null)
                {
                    tags.Add(existingTag);
                }
            }

            repository.InsertImage(new ImorImage
            {
                Uri         = request.Uri,
                Description = request.Description,
                Content     = request.Content,
                Tags        = tags
            });
        }
Exemplo n.º 2
0
        public IActionResult CurrentLikes(int id)
        {
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);

            return(Json(repo.GetLikesOfImage(id)));
        }
Exemplo n.º 3
0
        public IActionResult ViewImage(int id)
        {
            var  cookieValue        = Request.Cookies[$"{id}"];
            bool hasBeenHere        = cookieValue != null;
            SingleImageViewModel vm = new SingleImageViewModel();

            if (hasBeenHere)
            {
                vm.HasBeenHere = "disabled";
            }
            else
            {
                vm.HasBeenHere = "";
            }
            if (!hasBeenHere)
            {
                Response.Cookies.Append($"{id}", $"{id}");
            }
            var connectionString = _configuration.GetConnectionString("ConnectionString");
            var repository       = new ImagesRepository(connectionString);
            var image            = repository.GetById(id);

            vm.Image = image;
            return(View(vm));
        }
Exemplo n.º 4
0
        public ActionResult SlideSide()
        {
            V308CMSEntities  mEntities        = new V308CMSEntities();
            ImagesRepository imagesRepository = new ImagesRepository(mEntities);
            ImagesPage       mImagesPage      = new ImagesPage();
            Image            AnhTrai;
            Image            AnhPhai;
            StringBuilder    mStr         = new StringBuilder();
            CommonModel      mCommonModel = new CommonModel();

            try
            {
                AnhTrai              = imagesRepository.GetImageByTypeId(3, 1).FirstOrDefault();
                AnhPhai              = imagesRepository.GetImageByTypeId(2, 1).FirstOrDefault();
                mImagesPage.Html     = AnhTrai.LinkImage;
                mImagesPage.HtmlNhom = AnhPhai.LinkImage;
                return(View(mImagesPage));
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                return(Content("<h2>Có lỗi xảy ra trên hệ thống ! Vui lòng thử lại sau.</h2>"));
            }
            finally
            {
                mEntities.Dispose();
                imagesRepository.Dispose();
            }
        }
Exemplo n.º 5
0
        public ActionResult ViewImage(int id)
        {
            var db    = new ImagesRepository(Properties.Settings.Default.ConStr);
            var image = db.GetImage(id);

            if (image == null)
            {
                return(RedirectToAction("Index"));
            }

            var vm = new ViewImageViewModel
            {
                Image = image
            };

            if (Session["likedids"] != null)
            {
                var likedIds = (List <int>)Session["likedids"];
                //vm.CanLikeImage = !likedIds.Any(i => i == id);
                vm.CanLikeImage = likedIds.All(i => i != id);
            }
            else
            {
                vm.CanLikeImage = true;
            }
            return(View(vm));
        }
Exemplo n.º 6
0
        public ActionResult ViewImage(int?id)
        {
            var db = new ImagesRepository(_connectionString);

            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            var image = db.GetImage(id.Value);

            if (image == null)
            {
                return(RedirectToAction("Index"));
            }

            var vm = new ViewImageViewModel
            {
                Image = image
            };

            if (HttpContext.Session.GetString("likedids") != null)
            {
                var likedIds = HttpContext.Session.Get <List <int> >("likedids");
                //vm.CanLikeImage = !likedIds.Any(i => i == id);
                vm.CanLikeImage = likedIds.All(i => i != id);
            }
            else
            {
                vm.CanLikeImage = true;
            }
            return(View(vm));
        }
        public MasterPresenter(IMasterView masterView = null)
        {
            this.masterView = masterView;

            db = new PortalAukcyjnyEntities();

            if (IsUserLoggedIn())
            {
                currentUserId = GetCurrentUserId();
            }
            else
            {
                currentUserId = Guid.Empty;
            }

            currencyRepo   = new CurrencyExchangeRepository(db);
            auctionsRepo   = new AuctionsRepository(db);
            catRepo        = new CategoriesRepository(db);
            offersRepo     = new OffersRepository(db);
            usersRepo      = new UsersRepository(db);
            commentsRepo   = new CommentsRepository(db);
            observersRepo  = new ObserversRepository(db);
            shipmentsRepo  = new ShipmentsRepository(db);
            imagesRepo     = new ImagesRepository(db);
            buyedItemsRepo = new BuyedItemsRepository(db);
        }
Exemplo n.º 8
0
        public ActionResult ViewImage(int id)
        {
            var vm = new ViewImageViewModel();
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);
            var image            = repo.GetById(id);

            if (image == null)
            {
                return(RedirectToAction("Index"));
            }
            vm.Image = image;
            vm.Liked = false;

            List <string> ids = new List <string>();

            if (Request.Cookies["Ids"] != null)
            {
                ids = Request.Cookies["Ids"].Split(',').ToList();
            }

            if (ids.Contains(id.ToString()))
            {
                vm.Liked = true;
            }

            return(View(vm));
        }
        public IActionResult AddImage(Image image)
        {
            var repo = new ImagesRepository(_connectionString);

            repo.AddImage(image);
            return(Redirect("/"));
        }
Exemplo n.º 10
0
        public ImageBusiness(DatabaseFactory df = null, UnitOfWork uow = null)
        {
            DatabaseFactory dfactory = df == null ? new DatabaseFactory() : df;

            _unitOfWork        = uow == null ? new UnitOfWork(dfactory) : uow;
            _productRepository = new ProductRepository(dfactory);
            _imagesRepository  = new ImagesRepository(dfactory);
        }
Exemplo n.º 11
0
        public IActionResult GetCurrentLikes(int id)
        {
            var   connectionString = _configuration.GetConnectionString("ConStr");
            var   repo             = new ImagesRepository(connectionString);
            Image currentImage     = repo.GetById(id);

            return(Json(currentImage.Likes));
        }
Exemplo n.º 12
0
        public IActionResult GetLikes(int id)
        {
            var connectionString = _configuration.GetConnectionString("ConnectionString");
            var repository       = new ImagesRepository(connectionString);
            var image            = repository.GetById(id);

            return(Json(image.Likes));
        }
Exemplo n.º 13
0
        public IActionResult AddLike(int id)
        {
            var connectionString = _configuration.GetConnectionString("ConnectionString");
            var repository       = new ImagesRepository(connectionString);

            repository.AddLike(id);
            return(Json(id));
        }
Exemplo n.º 14
0
        public IActionResult GetAllImages()
        {
            var connectionString = _configuration.GetConnectionString("ConnectionString");
            var repository       = new ImagesRepository(connectionString);
            var images           = repository.GetAllImages();

            return(Json(images));
        }
Exemplo n.º 15
0
 private void CreateRepos()
 {
     mEntities        = new V308CMSEntities();
     ImageRepos       = new ImagesRepository(mEntities);
     ProductTypeRepos = new ProductTypeRepository(mEntities);
     ProductRepos     = new ProductRepository(mEntities);
     NewsRepos        = new NewsRepository(mEntities);
     MenuConfigRepos  = new MenuConfigRespository(mEntities);
 }
Exemplo n.º 16
0
        public IActionResult Upload(string title, IFormFile imageFile)
        {
            var fileName         = CreateImageAndStore(imageFile);
            var connectionString = _configuration.GetConnectionString("ConnectionString");
            var repository       = new ImagesRepository(connectionString);

            repository.AddImage(title, fileName);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 17
0
        public void LikeImage(int id)
        {
            var db = new ImagesRepository(_connectionString);

            db.AddLike(id);
            List <int> likedIds = HttpContext.Session.Get <List <int> >("likedids") ?? new List <int>();

            likedIds.Add(id);

            HttpContext.Session.Set("likedids", likedIds);
        }
Exemplo n.º 18
0
        private void GetImagesTest()
        {
            var repository = new ImagesRepository();

            var results = repository.GetImages();

            foreach (var result in results)
            {
                Console.WriteLine(JsonConvert.SerializeObject(result));
            }
        }
Exemplo n.º 19
0
        private void CreateRepos()
        {
            mEntities  = new V308CMSEntities();
            ImageRepos = new ImagesRepository(mEntities);

            ProductRepos = new ProductRepository(mEntities);
            AccountRepos = new AccountRepository(mEntities);
            NewsRepos    = new NewsRepository(mEntities);
            CommentRepo  = new TestimonialRepository(mEntities);
            CategoryRepo = new CategoryRepository(mEntities);
        }
Exemplo n.º 20
0
        public IActionResult Index()
        {
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);
            var vm = new ImagesViewModel()
            {
                Images = repo.GetImages()
            };

            return(View(vm));
        }
Exemplo n.º 21
0
        private void SearchImagesByTag()
        {
            var repo    = new ImagesRepository();
            var tagRepo = new TagsRepository();

            var results = repo.SearchImagesByTag("http://www.semanticweb.org/ImagesOntology#DogTag");

            foreach (var result in results)
            {
                Console.WriteLine(JsonConvert.SerializeObject(result));
            }
        }
        public byte[] GetImageBytes(int auctionId, int imageId)
        {
            ImagesRepository imagesRepo = new ImagesRepository();

            if (auctionId != -1)
            {
                return(imagesRepo.GetImageByAuctionId(auctionId));
            }
            else
            {
                return(imagesRepo.GetImageById(imageId));
            }
        }
        public IActionResult ViewImage(int imageId)
        {
            ViewImageViewModel vm = new ViewImageViewModel();

            if (HttpContext.Session.Get <List <int> >("imageIdsLiked") != null)
            {
                vm.ImageIdsLiked = HttpContext.Session.Get <List <int> >("imageIdsLiked");
            }
            var repo = new ImagesRepository(_connectionString);

            vm.Image = repo.GetImageById(imageId);
            return(View(vm));
        }
Exemplo n.º 24
0
        public ActionResult Menu()
        {
            V308CMSEntities        mEntities          = new V308CMSEntities();
            ProductRepository      productRepository  = new ProductRepository(mEntities);
            NewsRepository         newsRepository     = new NewsRepository(mEntities);
            List <ProductType>     mProductTypeParent = null;
            List <ProductTypePage> mProductTypePage   = new List <ProductTypePage>();
            News mNews;
            ProductTypePageContainer mProductTypePageContainer = new ProductTypePageContainer();
            ImagesRepository         imagesRepository          = new ImagesRepository(mEntities);
            List <Image>             mListImage;

            try
            {
                //lay danh sach nhom tin
                mProductTypeParent = productRepository.getProductTypeParent();
                //lay danh sach cac tin theo nhom
                foreach (ProductType it in mProductTypeParent)
                {
                    ProductTypePage vProductTypePage = new ProductTypePage();
                    vProductTypePage.Id    = it.ID;
                    vProductTypePage.Image = it.ImageBanner;
                    vProductTypePage.Name  = it.Name;
                    //lay danh sach cac nhom con
                    List <ProductType> mProductTypeChild = productRepository.LayNhomSanPhamTheoTrangVaSeri(1, 10, it.ID);
                    vProductTypePage.List = mProductTypeChild;
                    mProductTypePage.Add(vProductTypePage);
                    //
                    mProductTypePageContainer.List = mProductTypePage;
                    mNews = newsRepository.getFirstNewsWithType(16);
                    mProductTypePageContainer.mNews = mNews;
                    //lay danh sach
                    mListImage = imagesRepository.GetImageByTypeId(1, 4);
                    mProductTypePageContainer.ImageList = mListImage;
                }
                return(View(mProductTypePageContainer));
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                return(Content("<dx></dx>"));
            }
            finally
            {
                mEntities.Dispose();
                productRepository.Dispose();
            }
        }
Exemplo n.º 25
0
        public ActionResult Upload(Image image, IFormFile imageFile)
        {
            var    fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}";
            string fullPath = Path.Combine(_environment.WebRootPath, "uploads", fileName);

            using (FileStream stream = new FileStream(fullPath, FileMode.CreateNew))
            {
                imageFile.CopyTo(stream);
            }
            image.FileName = fileName;
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);

            repo.Add(image);
            return(Redirect("/home/index"));
        }
Exemplo n.º 26
0
        public IActionResult ViewImage(int id)
        {
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);
            var ids = HttpContext.Session.Get <List <int> >("Like-Ids");
            var vm  = new ViewImageViewModel()
            {
                Image = repo.GetById(id)
            };

            if (ids != null)
            {
                vm.Liked = ids.Contains(id);
            }
            return(View(vm));
        }
Exemplo n.º 27
0
        public IActionResult AddLike(int id)
        {
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);

            repo.AddLike(id);
            var session = HttpContext.Session.Get <List <int> >("Like-Ids");

            if (session == null)
            {
                session = new List <int>();
            }
            session.Add(id);
            HttpContext.Session.Set("Like-Ids", session);
            return(Json(id));
        }
Exemplo n.º 28
0
        public ActionResult Upload(string title, HttpPostedFileBase imageFile)
        {
            var fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}";

            imageFile.SaveAs(Path.Combine(Server.MapPath("/UploadedImages"), fileName));
            var image = new Image
            {
                Title        = title,
                FileName     = fileName,
                DateUploaded = DateTime.Now
            };
            var db = new ImagesRepository(Properties.Settings.Default.ConStr);

            db.Add(image);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 29
0
        public IActionResult Upload(string title, IFormFile imageFile)
        {
            var    fileName = $"{Guid.NewGuid()}{Path.GetExtension(imageFile.FileName)}";
            string fullPath = Path.Combine(_environment.WebRootPath, "uploads", fileName);

            using (FileStream stream = new FileStream(fullPath, FileMode.CreateNew))
            {
                imageFile.CopyTo(stream);
            }
            var image = new Image {
                Address = fileName, Title = title, DateUploaded = DateTime.Now
            };
            var connectionString = _configuration.GetConnectionString("ConStr");
            var repo             = new ImagesRepository(connectionString);

            repo.AddImage(image);
            return(Redirect("/"));
        }
Exemplo n.º 30
0
        public IActionResult Update(int id)
        {
            var   connectionString = _configuration.GetConnectionString("ConStr");
            var   repo             = new ImagesRepository(connectionString);
            Image currentImage     = repo.GetById(id);

            repo.UpdateLikes(currentImage);

            string ids    = "";
            var    cookie = Request.Cookies["Ids"];

            if (cookie != null)
            {
                ids = $"{cookie},";
            }
            ids += id;
            Response.Cookies.Append("Ids", ids);
            return(Json(currentImage.Likes));
        }