Beispiel #1
0
        public ActionResult newimages(HttpPostedFileBase file, string size, string Product, string PharmaF, string Category, string Division, string Edition)
        {
            try
            {
                CountriesUsers pp            = (CountriesUsers)Session["CountriesUsers"];
                int            ApplicationId = pp.ApplicationId;
                int            UsersId       = pp.userId;

                ProductImages ProductImages = new Models.ProductImages();

                int SizeId       = int.Parse(size);
                int ProductId    = int.Parse(Product);
                int PharmaFormId = int.Parse(PharmaF);
                int CategoryId   = int.Parse(Category);
                int DivisionId   = int.Parse(Division);
                int EditionId    = int.Parse(Edition);

                String FileName  = Path.GetFileName(file.FileName);
                String extention = Path.GetExtension(file.FileName);

                FileName = FileName.Replace(extention, "");

                var prods = (from p in db.Products
                             where p.ProductId == ProductId
                             select p).ToList();
                foreach (Products _prods in prods)
                {
                    FileName = _prods.ProductName.Trim().ToUpper();
                }

                FileName = ReplacesImageNames.replaces(FileName);

                FileName = FileName + extention;

                var img = (from _ims in db.ImageSizes
                           where _ims.ImageSizeId == SizeId
                           select _ims).ToList();
                foreach (ImageSizes _img in img)
                {
                    var root = Path.Combine(Server.MapPath("~/App_Data/uploads/ProductShots"), _img.Size);
                    var path = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["Path3"], _img.Size);
                    if (System.IO.Directory.Exists(root))
                    {
                        //path = path + "\\" + FileName;
                        root = root + "\\" + FileName;
                        //file.SaveAs(path);
                        file.SaveAs(root);
                    }
                    else
                    {
                        DirectoryInfo Dir = Directory.CreateDirectory(root);
                        root = Path.Combine(root, FileName);
                        file.SaveAs(root);

                        if (System.IO.Directory.Exists(root))
                        {
                            root = root + "\\" + FileName;
                            file.SaveAs(root);
                        }
                        //else
                        //{
                        //    DirectoryInfo Dirs = Directory.CreateDirectory(root);
                        //    root = Path.Combine(root, FileName);
                        //    file.SaveAs(root);
                        //}
                    }
                }

                var edp = (from _edp in db.ProductCategories
                           where _edp.CategoryId == CategoryId &&
                           _edp.DivisionId == DivisionId &&
                           _edp.PharmaFormId == PharmaFormId &&
                           _edp.ProductId == ProductId
                           select _edp).ToList();
                if (edp.LongCount() > 0)
                {
                    var eps = (from _eps in db.ProductImages
                               where _eps.CategoryId == CategoryId &&
                               _eps.DivisionId == DivisionId &&
                               _eps.PharmaFormId == PharmaFormId &&
                               _eps.ProductId == ProductId &&
                               _eps.ProductShot == FileName
                               select _eps).ToList();

                    if (eps.LongCount() == 0)
                    {
                        ProductImages.Active       = true;
                        ProductImages.CategoryId   = CategoryId;
                        ProductImages.DivisionId   = DivisionId;
                        ProductImages.PharmaFormId = PharmaFormId;
                        ProductImages.ProductId    = ProductId;
                        ProductImages.ProductShot  = FileName;
                        ProductImages.BaseURL      = null;

                        db.ProductImages.Add(ProductImages);
                        db.SaveChanges();



                        var epss = (from _eps in db.ProductImages
                                    where _eps.CategoryId == CategoryId &&
                                    _eps.DivisionId == DivisionId &&
                                    _eps.PharmaFormId == PharmaFormId &&
                                    _eps.ProductId == ProductId &&
                                    _eps.ProductShot == FileName
                                    select _eps).ToList();
                        int ProductImageSizeId = 0;
                        foreach (ProductImages _epss in epss)
                        {
                            ProductImageSizeId = _epss.ProductImageId;

                            var pis = (from _pis in db.ProductImageSizes
                                       where _pis.ImageSizeId == SizeId &&
                                       _pis.ProductImageId == _epss.ProductImageId
                                       select _pis).ToList();
                            if (pis.LongCount() == 0)
                            {
                                ProductImageSizes ProductImageSizes = new ProductImageSizes();

                                ProductImageSizes.ImageSizeId    = Convert.ToByte(SizeId);
                                ProductImageSizes.ProductImageId = _epss.ProductImageId;

                                db.ProductImageSizes.Add(ProductImageSizes);
                                db.SaveChanges();

                                ActivityLog._insertProductImageSizes(ProductImageSizeId, SizeId, ApplicationId, UsersId);
                            }

                            ActivityLog._insertproductimages(ProductId, PharmaFormId, DivisionId, CategoryId, ProductImageSizeId, FileName, ApplicationId, UsersId);
                        }
                    }
                    else
                    {
                        var epss = (from _eps in db.ProductImages
                                    where _eps.CategoryId == CategoryId &&
                                    _eps.DivisionId == DivisionId &&
                                    _eps.PharmaFormId == PharmaFormId &&
                                    _eps.ProductId == ProductId &&
                                    _eps.ProductShot == FileName
                                    select _eps).ToList();
                        int ProductImageSizeId = 0;
                        foreach (ProductImages _epss in epss)
                        {
                            ProductImageSizeId = _epss.ProductImageId;

                            var pis = (from _pis in db.ProductImageSizes
                                       where _pis.ImageSizeId == SizeId &&
                                       _pis.ProductImageId == _epss.ProductImageId
                                       select _pis).ToList();
                            if (pis.LongCount() == 0)
                            {
                                ProductImageSizes ProductImageSizes = new ProductImageSizes();

                                ProductImageSizes.ImageSizeId    = Convert.ToByte(SizeId);
                                ProductImageSizes.ProductImageId = _epss.ProductImageId;

                                db.ProductImageSizes.Add(ProductImageSizes);
                                db.SaveChanges();

                                ActivityLog._insertProductImageSizes(ProductImageSizeId, SizeId, ApplicationId, UsersId);
                            }
                        }
                        ProductImages.ProductShot = FileName;
                        db.SaveChanges();

                        ActivityLog._updateproductimages(ProductId, PharmaFormId, DivisionId, CategoryId, ProductImageSizeId, FileName, ApplicationId, UsersId);
                    }
                }
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                String msg = e.Message;
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public ActionResult newimages(HttpPostedFileBase file)
        {
            CountriesUsers p             = (CountriesUsers)Session["CountriesUsers"];
            int            ApplicationId = p.ApplicationId;
            int            UsersId       = p.userId;

            string      Size        = "";
            DivInfoId   D           = (DivInfoId)Session["DivInfoId"];
            int         DivisionId  = D.DivisionId;
            ImagesSizes IMSZ        = (ImagesSizes)Session["ImagesSizes"];
            int         ImageSizeId = IMSZ.SizeId;

            string img       = Path.GetFileName(file.FileName);
            var    extension = Path.GetExtension(file.FileName);

            string ID = "";

            var DI = from DivImg in db.Divisions
                     where DivImg.DivisionId == DivisionId
                     select DivImg;

            foreach (Divisions Divs in DI)
            {
                img = Divs.ShortName;

                var c = (from country in db.Countries
                         where country.CountryId == Divs.CountryId
                         select country).ToList();
                foreach (Countries _c in c)
                {
                    ID = _c.ID;
                }
            }
            img = ReplacesImageNames.replaces(img);

            var ImagesS = (from ImagesSize in db.ImageSizes
                           where ImagesSize.ImageSizeId == ImageSizeId
                           select ImagesSize).ToList();

            foreach (ImageSizes IS in ImagesS)
            {
                Size = IS.Size;

                if (IS.ImageSizeId == ImageSizeId)
                {
                    img = img + extension;
                    var path = Server.MapPath("~/App_Data/DivisionImages/" + ID + "");

                    if (System.IO.Directory.Exists(path))
                    {
                        var root = Path.Combine(path, Size);

                        if (System.IO.Directory.Exists(root))
                        {
                            var rt = Path.Combine(root, img);

                            file.SaveAs(rt);
                        }
                        else
                        {
                            var rt = Path.Combine(root, img);

                            DirectoryInfo Dirs = Directory.CreateDirectory(root);

                            file.SaveAs(rt);
                        }
                    }
                    else
                    {
                        DirectoryInfo Dir = Directory.CreateDirectory(path);

                        var root = Path.Combine(path, Size);

                        if (System.IO.Directory.Exists(root))
                        {
                            var rt = Path.Combine(root, img);

                            file.SaveAs(rt);
                        }
                        else
                        {
                            var rt = Path.Combine(root, img);

                            DirectoryInfo Dirs = Directory.CreateDirectory(root);

                            file.SaveAs(rt);
                        }
                    }
                }
            }
            bool images = insimage.insertimages(img, DivisionId, ImageSizeId, ApplicationId, UsersId);

            return(Json(images, JsonRequestBehavior.AllowGet));
        }