Exemplo n.º 1
0
        public ActionResult AddImage(AddImageVM imageVM)
        {
            string uniqueFileName = null;

            if (imageVM.imageFile != null)
            {
                try
                {
                    string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + imageVM.imageFile.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        imageVM.imageFile.CopyTo(fileStream);
                    }
                    ImagesProduct images = new ImagesProduct();
                    images.ImagesString = uniqueFileName;
                    images.ProductId    = imageVM.id;
                    context.AddImage(images);

                    var idManhal = context.GetManahel(imageVM.id).Id;
                    return(RedirectToAction(nameof(Index), "Product", new { manhalID = idManhal }));
                }
                catch { }
            }
            return(View(imageVM));
        }
Exemplo n.º 2
0
        public ActionResult AddImage(int productID)
        {
            AddImageVM imageVM = new AddImageVM();

            imageVM.id = productID;
            return(View(imageVM));
        }
        public ActionResult SearchType(int id, string txtSearch)
        {
            ViewData["ManhalImage"] = new AddImageVM()
            {
                id = id, imageFile = null
            };
            Manahel manahel = context1.GetElement(id);

            if (manahel != null)
            {
                List <Khalias>       khalias   = context1.GetKhaliases(id).Where(a => a.KhaliaType == txtSearch).ToList();
                List <ImagesManahel> images    = context1.GetImages(id);
                ManhalDetailsVM      detailsVM = new ManhalDetailsVM();
                detailsVM.manhal         = manahel;
                detailsVM.khalias        = khalias;
                detailsVM.imagesManahels = images;

                return(View(nameof(Details), detailsVM));
            }
            return(NotFound());
        }
        // GET: Manahels/Details/5
        public ActionResult Details(int id)
        {
            ViewData["ManhalImage"] = new AddImageVM()
            {
                id = id, imageFile = null
            };
            Manahel manahel = context1.GetElement(id);

            if (manahel != null)
            {
                List <Khalias>       khalias   = context1.GetKhaliases(id);
                List <ImagesManahel> images    = context1.GetImages(id);
                ManhalDetailsVM      detailsVM = new ManhalDetailsVM();
                detailsVM.manhal         = manahel;
                detailsVM.khalias        = khalias;
                detailsVM.imagesManahels = images;

                return(View(detailsVM));
            }
            return(NotFound());

            //return View(manahel);
        }
        public ActionResult AddImage(AddImageVM imageVM)
        {
            string uniqueFileName = null;

            if (imageVM.imageFile != null)
            {
                try
                {
                    string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + imageVM.imageFile.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        imageVM.imageFile.CopyTo(fileStream);
                    }
                    ImagesManahel images = new ImagesManahel();
                    images.ImagesString = uniqueFileName;
                    images.ManahelId    = imageVM.id;
                    context1.AddImage(images);
                }
                catch { }
            }
            return(RedirectToAction("Details", "Manahels", new { id = imageVM.id }));
        }