Ejemplo n.º 1
0
 public ActionResult CreateSSD([Bind(Include = "ProductId,TypeID,Manufacturer,Name,Price,Speed,Capacity,Description")] SSDViewModel product, HttpPostedFileBase uploadImage)
 {
     if (product.Price < 1)
     {
         ModelState.AddModelError(string.Empty, "Цена не может быть негативной");
     }
     if (ModelState.IsValid)
     {
         byte[] imageData = null;
         var    pr        = new Product {
             Manufacturer = product.Manufacturer, Name = product.Name, Price = product.Price, TypeID = ProductType.SSD, Description = product.Description
         };
         if (uploadImage != null)
         {
             using (var binaryReader = new BinaryReader(uploadImage.InputStream))
             {
                 imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                 pr.Image  = imageData;
             }
         }
         db.Product.Add(pr);
         db.SaveChanges();
         var ssd = new SSD {
             ProductId = pr.ProductId, Speed = product.Speed, Capacity = product.Capacity
         };
         db.SSD.Add(ssd);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var ssd = _ssdService.GetSSD(id);

            if (ssd == null)
            {
                return(NotFound());
            }

            var model = new SSDViewModel()
            {
                Id   = ssd.Id,
                Name = ssd.Name,
                OuterMemoryInterfaceId  = ssd.OuterMemoryInterfaceId,
                MemorySize              = ssd.MemorySize,
                Description             = ssd.Description,
                OuterMemoryFormFactorId = ssd.OuterMemoryFormFactorId,
                ReadSpeed      = ssd.ReadSpeed,
                WriteSpeed     = ssd.WriteSpeed,
                ManufacturerId = ssd.ManufacturerId,
                Price          = ssd.Price,
                Manufacturer   = ssd.Manufacturer.Name,
                ImagePath      = "/Images/SSD/" + ssd.Image,
            };
            var outerMemoryInterfaces = _outerMemoryInterfaceService.GetOuterMemoryInterfaces();

            ViewBag.OuterMemoryInterfaces = new SelectList(outerMemoryInterfaces, "Id", "Name");
            var outerMemoryFormFactors = _outerMemoryFormFactorService.GetOuterMemoryFormFactors();

            ViewBag.OuterMemoryFormFactors = new SelectList(outerMemoryFormFactors, "Id", "Name");
            var manufacturers = _manufacturerService.GetManufacturers();

            ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name");
            return(View("Edit", model));
        }
Ejemplo n.º 3
0
        public ActionResult PartialDetails(int id)
        {
            var ssd = _ssdService.GetSSD(id);

            if (ssd == null)
            {
                return(NotFound());
            }
            var model = new SSDViewModel()
            {
                Id                      = ssd.Id,
                Name                    = ssd.Name,
                Description             = ssd.Description,
                ShortDescription        = string.IsNullOrEmpty(ssd.Description) ? "" : CreateShortDescription(ssd.Description),
                WriteSpeed              = ssd.WriteSpeed,
                WriteSpeedDisplay       = ssd.WriteSpeed + " МБ/c",
                ReadSpeed               = ssd.ReadSpeed,
                ReadSpeedDisplay        = ssd.ReadSpeed + " МБ",
                MemorySize              = ssd.MemorySize,
                MemorySizeDisplay       = CreateMemoryDescription(ssd.MemorySize),
                OuterMemoryFormFactorId = ssd.OuterMemoryFormFactorId,
                OuterMemoryFormFactor   = ssd.OuterMemoryFormFactor.Name,
                OuterMemoryInterfaceId  = ssd.OuterMemoryInterfaceId,
                OuterMemoryInterface    = ssd.OuterMemoryInterface.Name,
                ManufacturerId          = ssd.ManufacturerId,
                Manufacturer            = ssd.Manufacturer.Name,
                ImagePath               = "/Images/SSD/" + ssd.Image,
                Price                   = ssd.Price
            };

            return(PartialView("PartialDetails", model));
        }
Ejemplo n.º 4
0
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(SSDViewModel model)
        {
            var ssd = _ssdService.GetSSD(model.Id);

            if (ssd == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                ssd.Name = model.Name;
                ssd.OuterMemoryInterfaceId  = model.OuterMemoryInterfaceId;
                ssd.MemorySize              = model.MemorySize;
                ssd.Description             = model.Description;
                ssd.OuterMemoryFormFactorId = model.OuterMemoryFormFactorId;
                ssd.ReadSpeed      = model.ReadSpeed;
                ssd.WriteSpeed     = model.WriteSpeed;
                ssd.ManufacturerId = model.ManufacturerId;
                ssd.Price          = model.Price;

                if (model.Image != null)
                {
                    var helper = new ImageHelper(_webHostEnvironment);
                    var image  = helper.GetUploadedFile(model.Image, "SSD");
                    ssd.Image = image;
                }

                var result = _ssdService.UpdateSSD(ssd);

                model.Id    = ssd.Id;
                model.Image = null;

                if (result.Succedeed)
                {
                    return(View("../Catalog/Index", new { startView = "SSD" }));
                }

                return(NotFound(result));
            }
            var outerMemoryInterfaces = _outerMemoryInterfaceService.GetOuterMemoryInterfaces();

            ViewBag.OuterMemoryInterfaces = new SelectList(outerMemoryInterfaces, "Id", "Name");
            var outerMemoryFormFactors = _outerMemoryFormFactorService.GetOuterMemoryFormFactors();

            ViewBag.OuterMemoryFormFactors = new SelectList(outerMemoryFormFactors, "Id", "Name");
            var manufacturers = _manufacturerService.GetManufacturers();

            ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name");
            return(View("Edit", model));
        }
Ejemplo n.º 5
0
        public ActionResult SSDDetails(int?id)
        {
            SSDViewModel ssd = new SSDViewModel
            {
                ProductId    = (int)id,
                TypeID       = db.Product.Find(id).TypeID,
                Manufacturer = db.Product.Find(id).Manufacturer,
                Name         = db.Product.Find(id).Name,
                Price        = db.Product.Find(id).Price,
                Speed        = db.SSD.Find(id).Speed,
                Capacity     = db.SSD.Find(id).Capacity,
                Image        = db.Product.Find(id).Image,
                Description  = db.Product.Find(id).Description
            };

            return(View(ssd));
        }
Ejemplo n.º 6
0
        public IActionResult Create(SSDViewModel model)
        {
            if (ModelState.IsValid)
            {
                var helper = new ImageHelper(_webHostEnvironment);
                var image  = helper.GetUploadedFile(model.Image, "SSD");
                var ssd    = new SSD()
                {
                    Name = model.Name,
                    OuterMemoryInterfaceId  = model.OuterMemoryInterfaceId,
                    MemorySize              = model.MemorySize,
                    Description             = model.Description,
                    OuterMemoryFormFactorId = model.OuterMemoryFormFactorId,
                    ReadSpeed      = model.ReadSpeed,
                    WriteSpeed     = model.WriteSpeed,
                    ManufacturerId = model.ManufacturerId,
                    Price          = model.Price,
                    Image          = image
                };

                var result = _ssdService.CreateSSD(ssd);

                model.Id    = ssd.Id;
                model.Image = null;

                if (result.Succedeed)
                {
                    return(View("../Catalog/Index", new { startView = "SSD" }));
                }

                return(NotFound(result));
            }
            var outerMemoryInterfaces = _outerMemoryInterfaceService.GetOuterMemoryInterfaces();

            ViewBag.OuterMemoryInterfaces = new SelectList(outerMemoryInterfaces, "Id", "Name");
            var outerMemoryFormFactors = _outerMemoryFormFactorService.GetOuterMemoryFormFactors();

            ViewBag.OuterMemoryFormFactors = new SelectList(outerMemoryFormFactors, "Id", "Name");
            var manufacturers = _manufacturerService.GetManufacturers();

            ViewBag.Manufacturers = new SelectList(manufacturers, "Id", "Name");
            return(View(model));
        }
Ejemplo n.º 7
0
 public ActionResult SSDEdit([Bind(Include = "ProductId,TypeID,Manufacturer,Name,Price,Speed,Capacity,Description,Image")] SSDViewModel product, HttpPostedFileBase uploadImage)
 {
     if (product.Price < 1)
     {
         ModelState.AddModelError(string.Empty, "Цена не может быть негативной");
     }
     if (ModelState.IsValid)
     {
         byte[] imageData = null;
         if (uploadImage != null)
         {
             using (var binaryReader = new BinaryReader(uploadImage.InputStream))
             {
                 imageData     = binaryReader.ReadBytes(uploadImage.ContentLength);
                 product.Image = imageData;
             }
         }
         Product newP = new Product
         {
             ProductId    = product.ProductId,
             Manufacturer = product.Manufacturer,
             Name         = product.Name,
             Price        = product.Price,
             TypeID       = product.TypeID,
             Image        = product.Image,
             Description  = product.Description
         };
         SSD newS = new SSD
         {
             ProductId = product.ProductId,
             Capacity  = product.Capacity,
             Speed     = product.Speed
         };
         db.Entry(newP).State = EntityState.Modified;
         db.SaveChanges();
         db.Entry(newS).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }