예제 #1
0
        public void EditItem(IEnumerable <HttpPostedFileBase> uploads, AdminItem item)
        {
            string image  = item.Image;
            string image2 = item.Image2;
            string image3 = item.Image3;
            string image4 = item.Image4;

            int number = 0;

            foreach (var img in uploads)
            {
                if (img != null && number == 0)
                {
                    image = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                if (img != null && number == 1)
                {
                    image2 = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                if (img != null && number == 2)
                {
                    image3 = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                if (img != null && number == 3)
                {
                    image4 = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                number++;
            }

            var data =
                (from entry in _db.ItemsDB
                 where entry.Id == item.Id
                 select entry).ToList();

            foreach (var oldItem in data)
            {
                oldItem.NameUA        = item.NameUA;
                oldItem.NameRU        = item.NameRU;
                oldItem.NameEN        = item.NameEN;
                oldItem.CategoryUA    = item.CategoryUA;
                oldItem.CategoryRU    = item.CategoryRU;
                oldItem.CategoryEN    = item.CategoryEN;
                oldItem.Price         = item.Price;
                oldItem.DescriptionUA = item.DescriptionUA;
                oldItem.DescriptionRU = item.DescriptionRU;
                oldItem.DescriptionEN = item.DescriptionEN;
                oldItem.Image         = image;
                oldItem.Image2        = image2;
                oldItem.Image3        = image3;
                oldItem.Image4        = image4;
            }

            _db.SaveChanges();
        }
예제 #2
0
        public void AddItem(IEnumerable <HttpPostedFileBase> uploads, AdminItem item)
        {
            string image  = "no_image.png";
            string image2 = "no_image.png";
            string image3 = "no_image.png";
            string image4 = "no_image.png";

            int number = 0;

            foreach (var img in uploads)
            {
                if (img != null && number == 0)
                {
                    image = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                if (img != null && number == 1)
                {
                    image2 = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                if (img != null && number == 2)
                {
                    image3 = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                if (img != null && number == 3)
                {
                    image4 = img.FileName;
                    img.SaveAs(HttpContext.Current.Server.MapPath("~/Content/images/products/" + img.FileName));
                }
                number++;
            }

            _db.ItemsDB.Add(new DbItems
            {
                NameUA        = item.NameUA,
                NameRU        = item.NameRU,
                NameEN        = item.NameEN,
                CategoryUA    = item.CategoryUA,
                CategoryRU    = item.CategoryRU,
                CategoryEN    = item.CategoryEN,
                Image         = image,
                Image2        = image2,
                Image3        = image3,
                Image4        = image4,
                Price         = item.Price,
                DescriptionUA = item.DescriptionUA,
                DescriptionRU = item.DescriptionRU,
                DescriptionEN = item.DescriptionEN,
                orderCount    = 0,
            });

            _db.SaveChanges();
        }