public IActionResult Index() { var userid = _userManager.GetUserId(User); var memberproductid = _repository.Products.Where(x => x.MemberProductId == userid).ToList(); var viewImageList = new List <ViewImageViewModel>(); //convert the Products into readable type for the Model foreach (var product in memberproductid) { var viewImage = new ViewImageViewModel { ProductId = product.ProductId, Description = product.Description, Name = product.Name, Price = product.Price, ContentType = product.ContentType }; if (product.Image != null) { MemoryStream ms = new MemoryStream(product.Image); byte[] imageBytes = ms.ToArray(); viewImage.Image = Convert.ToBase64String(imageBytes); } viewImageList.Add(viewImage); } return(View(viewImageList)); }
//_repository.Products returns db.Products which is Products table from database //Includes all the products public IActionResult Index() { //procedure to View the Image and convert the _repository.Product to View Model var viewImageList = new List <ViewImageViewModel>(); //Show omly the approved Prducts var productsListsApproved = _repository.Products.Where(x => x.AdminApproved == true).ToList(); foreach (var product in productsListsApproved) { var viewImage = new ViewImageViewModel { ProductId = product.ProductId, Name = product.Name, Description = product.Description, Price = product.Price, ContentType = product.ContentType }; if (product.Image != null) { MemoryStream ms = new MemoryStream(product.Image); byte[] imageBytes = ms.ToArray(); viewImage.Image = Convert.ToBase64String(imageBytes); } viewImageList.Add(viewImage); } return(View(viewImageList)); }
public IActionResult ViewImage(int id) { var connectionString = _configuration.GetConnectionString("ConStr"); var repo = new ImageRepository(connectionString); var likedImages = HttpContext.Session.Get <List <int> >("likedImages"); var vm = new ViewImageViewModel { Image = repo.GetImage(id) }; if (likedImages != null) { vm.likedImages = likedImages; } if (likedImages != null && likedImages.Contains(id)) { vm.alreadyLiked = true; } else { vm.alreadyLiked = false; } return(View(vm)); }
public ActionResult ViewImage(int id) { var viewModel = new ViewImageViewModel(); if (TempData["message"] != null) { viewModel.Message = (string)TempData["message"]; } if (!HasPermissionToView(id)) { viewModel.HasPermissionToView = false; viewModel.Image = new Image { Id = id }; } else { viewModel.HasPermissionToView = true; var db = new ImageDb(Properties.Settings.Default.ConStr); db.IncrementViewCount(id); var image = db.GetById(id); if (image == null) { return(RedirectToAction("Index")); } viewModel.Image = image; } return(View(viewModel)); }
protected override void OnAppearing() { BindingContext = new ViewImageViewModel(Navigation, _image.Source.ToString().Substring(6)); // var streamReader = new StreamReader(_image.Source.ToString().Substring(6)); // var bytes = default(byte[]); //var memstream = new MemoryStream(); //streamReader.BaseStream.CopyTo(memstream); //bytes = memstream.ToArray(); //ViewImage.Source = ImageSource.FromStream(() => new MemoryStream(bytes)); // ViewImage = new Image { Source = ImageSource.FromStream(() => new MemoryStream(bytes)) }; // ViewImage.Source = ImageSource.FromFile(_image.Source.ToString().Substring(6)); //ViewImage = new Image //{ // Source = ImageSource.FromFile(_image.Source.ToString().Substring(6)) //}; //_image.Source.ToString().Substring(6) base.OnAppearing(); }
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 Index() { //Turn repo.Products into a List of View Model to return in the View var viewImageList = new List <ViewImageViewModel>(); //Show omly the approved Prducts var productsListsApproved = _repository.Products.Where(x => x.AdminApproved == true).ToList(); foreach (var product in productsListsApproved) { var viewImage = new ViewImageViewModel { ProductId = product.ProductId, Name = product.Name, Description = product.Description, Price = product.Price, ContentType = product.ContentType }; if (product.Image != null) { var ms = new MemoryStream(product.Image); byte[] imageBytes = ms.ToArray(); viewImage.Image = Convert.ToBase64String(imageBytes); } viewImageList.Add(viewImage); } //HttpContext.Session.SetString("Data", "From session");//Do we need this? return(View(viewImageList)); }
public ActionResult ViewImage(int id) { var viewModel = new ViewImageViewModel(); if (TempData["message"] != null) { viewModel.Message = (string)TempData["message"]; } if (!HasPermissionToView(id)) { viewModel.HasPermissionToView = false; viewModel.Image = new Image { Id = id }; } else { viewModel.HasPermissionToView = true; db.UpdateViewsCount(id); var image = db.GetImage(id); if (image == null) { return(RedirectToAction("Index")); } viewModel.Image = image; } return(View(viewModel)); }
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 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)); }
public ActionResult ViewImage(int id, string password) { ViewImageViewModel vm = new ViewImageViewModel(); Image image = mgr.GetImage(id); if (image.Id == 0) { vm.IncorrectPassword = true; } if (Session["pw"] == null) { Session["pw"] = new List <int>(); } List <int> images = (List <int>)Session["pw"]; foreach (int i in images) { if (i == id) { password = image.Password; } } //if (Session[$"pw-{id}"] != null) //{ // password = image.Password; //} vm.Image = image; if (password == null) { vm.Password = null; vm.IncorrectPassword = true; } else { if (password != image.Password) { vm.Password = password; vm.IncorrectPassword = true; } else { vm.Password = password; vm.IncorrectPassword = false; vm.Image.Views = mgr.IncrementCount(id); // Session[$"pw-{id}"] = password; images.Add(id); } } return(View(vm)); }
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)); }
public IActionResult ViewImage(int imageId, string password, bool enteredPassword) { ViewImageViewModel vm = new ViewImageViewModel(); List <int> ids = HttpContext.Session.Get <List <int> >("imageIds"); bool contains = false; if (ids != null) { var currentId = ids.FirstOrDefault(i => i == imageId); if (currentId > 0) { password = ""; enteredPassword = true; contains = true; } } if (password == null) { vm.imageId = imageId; vm.EnteredPassword = enteredPassword; return(View(vm)); } DbManager db = new DbManager(_connectionString); bool correct = db.CorrectPassword(imageId, password); if (correct || contains) { db.UpdateViews(imageId); Image image = db.GetImage(imageId); vm.CorrectPassword = true; vm.EnteredPassword = true; if (HttpContext.Session.Get <List <int> >("imageIds") == null) { List <int> imageIds = new List <int>(); HttpContext.Session.Set("imageIds", imageIds); } List <int> newList = HttpContext.Session.Get <List <int> >("imageIds"); newList.Add(image.ID); HttpContext.Session.Set("imageIds", newList); vm.Image = image; } else if (!correct) { return(Redirect($"/home/viewImage?imageId={imageId}&enteredPassword=true")); } return(View(vm)); }
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)); }
public ActionResult ViewImage(int imageId) { var viewModel = new ViewImageViewModel { Image = repo.GetById(imageId) }; if (HasPermissionToLike(imageId)) { viewModel.HasPermissionToLike = true; } else { viewModel.HasPermissionToLike = false; } return(View(viewModel)); }
public IActionResult ViewImage(int Id, string Password) { ImagesDb db = new ImagesDb(_connectionString); var ids = HttpContext.Session.Get <List <int> >("Ids"); if (ids == null) { ids = new List <int>(); } var InSession = ids.Any(i => i == Id); var image = db.GetImage(Id); bool CorrectPassword = image.Password == Password; var message = (TempData["message"] != null); bool showImage = InSession || CorrectPassword; if (showImage) { db.UpdateImageViews(Id); } if (!InSession && CorrectPassword) { ids.Add(Id); HttpContext.Session.Set("Ids", ids); } ViewImageViewModel vm = new ViewImageViewModel { ShowMessage = message, ShowImage = showImage, Image = image }; if (TempData["message"] != null) { return(View(vm)); } if (Password != null) { TempData["message"] = "Invalid password"; message = true; return(Redirect($"/home/viewImage?id={Id}")); } return(View(vm)); }
public IActionResult ViewImage(int id, string password) { var db = new Imagesdb(_connectionString); var ids = HttpContext.Session.Get <List <int> >("ids"); if (ids == null) { ids = new List <int>(); } var sessionInProgress = ids.Any(i => i == id); Image img = db.GetImageById(id); bool correct = img.Password == password; bool msg = false; if (password != null) { msg = true; } bool showImage = sessionInProgress || correct; if (showImage) { db.UpdateViews(id); } if (!sessionInProgress || correct) { ids.Add(id); HttpContext.Session.Set("ids", ids); } var vm = new ViewImageViewModel() { Image = img, ShowImage = showImage, ShowMessage = msg }; return(View(vm)); }
//Θα καλειται οταν ο client κλικαρει σε ενα προιον και θα του το εμφανιζει μονο του με τα details public IActionResult ViewProduct(int productId) { ViewBag.Data = HttpContext.Session.GetString("Data"); var product = _repository.Products.FirstOrDefault(p => p.ProductId == productId); //Image Procedure for the Main Product of the View var viewImage = new ViewImageViewModel(); if (product.Image != null) { var ms = new MemoryStream(product.Image); byte[] imageBytes = ms.ToArray(); viewImage.Image = Convert.ToBase64String(imageBytes); } List <Products> similarProducts = _repository.Products.Where(i => i.Category == product.Category).ToList(); //Image Procedure for the Same Category Products of the view var similarViewImageList = new List <ViewImageViewModel>(); foreach (var prod in similarProducts) { var similarViewImage = new ViewImageViewModel { ProductId = prod.ProductId, Name = prod.Name, Description = prod.Description, Price = prod.Price, ContentType = prod.ContentType }; if (prod.Image != null) { var ms = new MemoryStream(prod.Image); byte[] imageBytes = ms.ToArray(); similarViewImage.Image = Convert.ToBase64String(imageBytes); } similarViewImageList.Add(similarViewImage); } SameCategoryViewModel sameCategory = new SameCategoryViewModel(product, similarProducts, viewImage, similarViewImageList); return(View(sameCategory)); }