예제 #1
0
        public ActionResult ProductDelete(long productId)
        {
            RS_PRODUCT deletedProduct = repository.DeleteProduct(productId);

            if (deletedProduct != null)
            {
                TempData["message"] = string.Format("{0} был удален", deletedProduct.Name);
            }
            return(RedirectToAction("Products"));
        }
예제 #2
0
        public RS_PRODUCT DeleteProduct(long productId)
        {
            RS_PRODUCT dbEntry = context.RS_PRODUCT.Where(x => x.ProductId == productId).Single();

            if (dbEntry != null)
            {
                context.RS_PRODUCT.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
예제 #3
0
        public ViewResult ProductEdit(long productId)
        {
            RS_PRODUCT product = repository.Productts.Where(p => p.ProductId == productId).FirstOrDefault();
            IEnumerable <SK_EQUIPMENT> equipments = repository.Equipments;
            IEnumerable <SK_MODEL>     models     = repository.Models;
            CT_IMAGE image = repository.Images.Where(i => i.ImageId == product.ImageId).FirstOrDefault();

            ProductViewModel productVM = new ProductViewModel
            {
                Product    = product,
                Equipments = equipments,
                Models     = models
            };

            productVM.Product.CT_IMAGE = image;

            return(View(productVM));
        }
예제 #4
0
        public void ClearImage(long productId)
        {
            long?imageId = context.RS_PRODUCT.Where(x => x.ProductId == productId).SingleOrDefault().ImageId;

            if (imageId != null)
            {
                RS_PRODUCT dbEntryPrd = context.RS_PRODUCT.Where(x => x.ProductId == productId).Single();
                if (dbEntryPrd != null)
                {
                    dbEntryPrd.ImageId  = null;
                    dbEntryPrd.CT_IMAGE = null;
                    context.SaveChanges();
                }

                CT_IMAGE dbEntryImg = context.CT_IMAGE.Where(x => x.ImageId == imageId).Single();
                if (dbEntryImg != null)
                {
                    context.CT_IMAGE.Remove(dbEntryImg);
                    context.SaveChanges();
                }
            }
        }
예제 #5
0
        public ActionResult DownLoadFile(long productId)
        {
            RS_PRODUCT product = repository.Productts.Where(p => p.ProductId == productId).FirstOrDefault();
            IEnumerable <SK_EQUIPMENT> equipments = repository.Equipments;
            IEnumerable <SK_MODEL>     models     = repository.Models;
            CT_IMAGE image = repository.Images.Where(i => i.ImageId == product.ImageId).FirstOrDefault();

            ProductViewModel productVM = new ProductViewModel
            {
                Product    = product,
                Equipments = equipments,
                Models     = models
            };

            productVM.Product.CT_IMAGE = image;

            if (image != null && image.Data != null && image.MimeType != null)
            {
                return(File(image.Data, image.MimeType, image.FileName));
            }

            return(View("ProductEdit", productVM));
        }
예제 #6
0
        public void SaveProduct(RS_PRODUCT product)
        {
            //image
            CT_IMAGE img      = null;
            DateTime dateLoad = DateTime.Now;

            if (product.CT_IMAGE.Data != null)
            {
                if (product.ImageId != null)
                {
                    img          = context.CT_IMAGE.Where(x => x.ImageId == product.ImageId).Single();
                    img.Data     = product.CT_IMAGE.Data;
                    img.MimeType = product.CT_IMAGE.MimeType;
                    img.FileName = product.CT_IMAGE.FileName;
                    img.Size     = product.CT_IMAGE.Size;
                    img.DateLoad = dateLoad;
                }
                else
                {
                    img          = new CT_IMAGE();
                    img.Data     = product.CT_IMAGE.Data;
                    img.MimeType = product.CT_IMAGE.MimeType;
                    img.FileName = product.CT_IMAGE.FileName;
                    img.Size     = product.CT_IMAGE.Size;
                    img.DateLoad = dateLoad;
                    context.CT_IMAGE.Add(img);
                }
                context.SaveChanges();
            }
            else
            {
                if (product.ImageId != null)
                {
                    img = context.CT_IMAGE.Where(x => x.ImageId == product.ImageId).Single();
                }
            }

            //PRODUCT
            product.ImageId  = img != null ? img.ImageId : (long?)null;
            product.CT_IMAGE = img;

            if (product.ProductId == 0)
            {
                context.RS_PRODUCT.Add(product);
            }
            else
            {
                RS_PRODUCT dbEntry = context.RS_PRODUCT.Where(x => x.ProductId == product.ProductId).Single();
                if (dbEntry != null)
                {
                    dbEntry.EquipmentId = product.EquipmentId;
                    dbEntry.ModelId     = product.ModelId;
                    dbEntry.ImageId     = product.ImageId;

                    dbEntry.Name     = product.Name;
                    dbEntry.Descr    = product.Descr;
                    dbEntry.Mass     = product.Mass;
                    dbEntry.Length   = product.Length;
                    dbEntry.Width    = product.Width;
                    dbEntry.Height   = product.Height;
                    dbEntry.Color    = product.Color;
                    dbEntry.Power    = product.Power;
                    dbEntry.Kit      = product.Kit;
                    dbEntry.IsActive = product.IsActive;

                    dbEntry.SK_EQUIPMENT = product.SK_EQUIPMENT;
                    dbEntry.SK_MODEL     = product.SK_MODEL;
                    dbEntry.CT_IMAGE     = product.CT_IMAGE;
                }
            }
            context.SaveChanges();
        }