Пример #1
0
        public void Create_Catalog_Valid_If_All_Is_Correct()
        {
            // arrange
            Catalog catalog = new Catalog
            {
                Code = "TEST01",
                Name = "Test Bracer",
                Description = "Description Test Bracer",
                Price = 12000,
                ImageUrl = "~/Content/images/pic1.jpg"
            };

            var catalogMock = new Mock<ICatalog>();
            catalogMock.Setup(x => x.CreateCatalog(catalog));
        }
Пример #2
0
        public ActionResult Create(CatalogView catalogview)
        {
            if (ModelState.IsValid)
            {
                //foreach (string file in Request.Files)
                //{
                //    HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                //    if (hpf.ContentLength == 0)
                //        continue;
                //    string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/images/", Path.GetFileName(hpf.FileName));
                //    hpf.SaveAs(savedFileName);
                //    catalog.ImageUrl = "~/Content/images/" + Path.GetFileName(hpf.FileName);
                //}

                Int32 length = catalogview.FileUpload.ContentLength;

                Catalog catalog = new Catalog();

                byte[] tempImage = new byte[length];
                catalogview.FileUpload.InputStream.Read(tempImage, 0, length);

                //fill in the catalog model
                catalog.Code = catalogview.Code;
                catalog.Name = catalogview.Name;
                catalog.Price = catalogview.Price;
                catalog.Description = catalogview.Description;
                catalog.CategoryId = catalogview.CategoryId;
                catalog.ImageData = tempImage;
                catalog.ContentType = catalogview.FileUpload.ContentType;

                catalogRepo.CreateCatalog(catalog);
                catalogRepo.Save();
                return RedirectToAction("Index");
            }

            return View(catalogview);
        }
Пример #3
0
 public void EditCatalog(Catalog catalogEditValue, Catalog catalogOriginal)
 {
     db.Entry(catalogOriginal).CurrentValues.SetValues(catalogEditValue);
 }
Пример #4
0
 public void CreateCatalog(Catalog catalogToCreate)
 {
     db.Catalogs.Add(catalogToCreate);
 }
Пример #5
0
        public ActionResult Edit(string code, CatalogView catalogview)
        {
            Catalog ctlg = catalogRepo.GetCatalogByCode(code);
            if (ModelState.IsValid)
            {
                //foreach (string file in Request.Files)
                //{
                //    HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                //    if (hpf.ContentLength == 0)
                //        continue;
                //    string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/images/", Path.GetFileName(hpf.FileName));
                //    hpf.SaveAs(savedFileName);
                //    catalog.ImageUrl = "~/Content/images/" + Path.GetFileName(hpf.FileName);
                //}
                //if (ctlg.ImageUrl != "" && (catalog.ImageUrl == "" || catalog.ImageUrl == null))
                //{
                //    catalog.ImageUrl = ctlg.ImageUrl;
                //}

                Catalog catalog = new Catalog();

                catalog.Code = catalogview.Code;
                catalog.Name = catalogview.Name;
                catalog.Price = catalogview.Price;
                catalog.Description = catalogview.Description;
                catalog.CategoryId = catalogview.CategoryId;
                catalog.CategoryDetail = catalogview.CategoryDetail;

                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    Int32 length = file.ContentLength;

                    catalog.ContentType = file.ContentType;
                    byte[] tempImage = new byte[length];
                    file.InputStream.Read(tempImage, 0, length);
                    catalog.ImageData = tempImage;
                }
                else
                {
                    catalog.ImageData = ctlg.ImageData;
                    catalog.ContentType = ctlg.ContentType;
                }

                //db.Entry(catalog).State = EntityState.Modified;
                catalogRepo.EditCatalog(catalog, ctlg);
                catalogRepo.Save();
                return RedirectToAction("Index");
            }

            return View(catalogview);
        }