Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
Beispiel #1
0
        public async Task <IActionResult> Update(ProductPhotoUpdateViewModel productPhotoUpdateViewModel, IFormFile photo, string pht)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    string NameAndPath = Path.Combine(_iHostingEnvironment.WebRootPath +
                                                      "/product_photo", Path.GetFileName(photo.FileName));

                    await photo.CopyToAsync(new FileStream (NameAndPath, FileMode.Create));

                    productPhotoUpdateViewModel.Photo = "product_photo/" + photo.FileName;
                }
                if (photo == null)
                {
                    productPhotoUpdateViewModel.Photo = pht;
                }

                ProductPhoto updateProductPhoto = _iMapper.Map <ProductPhoto>(productPhotoUpdateViewModel);
                bool         IsAdd = await _iProductPhotoManager.Update(updateProductPhoto);

                if (IsAdd)
                {
                    return(RedirectToAction("Index2", new { id = updateProductPhoto.ProductId }));
                }

                ViewBag.ErrorMessage = "Failed to Update Product Photo";
            }
            return(View(productPhotoUpdateViewModel));
        }
Beispiel #2
0
        /// <summary>
        /// Обновить фотографию
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> UpdateProductPhoto()
        {
            using (MarketBotDbContext db = new MarketBotDbContext())
            {
                var    product  = db.Product.Where(p => p.Id == ProductGet(ProductEditPhotoReply)).FirstOrDefault();
                string NewPhoto = base.PhotoId;

                int fs_id = await base.InsertToAttachmentFs(base.PhotoId);

                ProductPhoto productPhoto = new ProductPhoto
                {
                    AttachmentFsId = fs_id,
                    ProductId      = product.Id
                };

                AttachmentTelegram attachment = new AttachmentTelegram
                {
                    AttachmentFsId = fs_id,
                    FileId         = base.PhotoId,
                    BotInfoId      = BotInfo.Id,
                };

                db.ProductPhoto.Add(productPhoto);
                db.AttachmentTelegram.Add(attachment);
                db.SaveChanges();

                return(await SendProductFunc(product));
            }
        }
        public ActionResult Edit(ProductViewModel model, HttpPostedFileBase UploadedPhoto)
        {
            if (ModelState.IsValid)
            {
                // Mapping current ProductViewModel for ProductModel
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <ProductViewModel, ProductModel>();
                });
                IMapper mapper = config.CreateMapper();
                var     item   = mapper.Map <ProductViewModel, ProductModel>(model);


                // Processing input photo file to add to DB

                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    if (UploadedPhoto != null && UploadedPhoto.ContentLength != 0)
                    {
                        var oldPhoto = db.Photos.Find(item.ProductId);
                        db.Photos.Remove(oldPhoto);
                        ProductPhoto productPhoto = new ProductPhoto();
                        productPhoto.MimeType = UploadedPhoto.ContentType;
                        productPhoto.Photo    = new byte[UploadedPhoto.ContentLength];
                        UploadedPhoto.InputStream.Read(productPhoto.Photo, 0, UploadedPhoto.ContentLength);
                        productPhoto.ProductId = item.ProductId;
                        db.Photos.Add(productPhoto);
                    }
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Get", "Product", new { id = item.ProductId }));
                }
            }
            return(View(model));
        }
Beispiel #4
0
        public IActionResult PhotoUpload()
        {
            IFormFileCollection files = Request.Form.Files;

            var productId = Convert.ToInt32(Request.Form["prdId"].ToString());

            if (files.Count > 0)
            {
                foreach (var file in files)
                {
                    var randomFileName = RandomValueGenerator.GenerateFileName(Path.GetExtension(file.FileName));


                    string uploadPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/AdminPanelContent/images/ProductPhotos", randomFileName);

                    using (var stream = new FileStream(uploadPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }

                    ProductPhoto photo = new ProductPhoto();
                    photo.ProductId = productId;
                    photo.PhotoPath = "/AdminPanelContent/images/ProductPhotos/" + randomFileName;

                    _productPhotoBs.Insert(photo);
                }
                return(Json(new { IsOk = true }));
            }

            return(Json(new { IsOk = false }));
        }
        public ActionResult Add(ProductViewModel m, HttpPostedFileBase Photo)
        {
            if (ModelState.IsValid)
            {
                // Mapping current ProductViewModel for ProductModel
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <ProductViewModel, ProductModel>();
                });
                IMapper mapper = config.CreateMapper();
                var     item   = mapper.Map <ProductViewModel, ProductModel>(m);


                ProductPhoto productPhoto = new ProductPhoto();
                // Processing input photo file to add to DB
                if (Photo != null && Photo.ContentLength != 0)
                {
                    productPhoto.MimeType = Photo.ContentType;
                    productPhoto.Photo    = new byte[Photo.ContentLength];
                    Photo.InputStream.Read(productPhoto.Photo, 0, Photo.ContentLength);
                }
                item.Photo = productPhoto;
                // Saving Product in DB
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    db.Products.Add(item);
                    db.SaveChanges();
                }
                return(RedirectToAction("List", new { category = item.Category }));
            }
            return(View(m));
        }
        public IActionResult Delete(int?id)
        {
            if (HttpContext.Session.GetString("AdminId") != null)
            {
                if (id == null)
                {
                    return(NotFound());
                }

                ProductPhoto aProductPhotoInfo = _iProductPhotoManager.GetById(id);
                int          productId         = aProductPhotoInfo.ProductId;

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

                bool isRemove = _iProductPhotoManager.Remove(aProductPhotoInfo);

                if (isRemove)
                {
                    return(RedirectToAction("AllProductImage", "Product", new { id = productId }));
                }
                else
                {
                    ViewBag.ErrorMessage = "Product photo remove has been failed! Try again.";
                }
            }

            return(RedirectToAction("Index", "Login"));
        }
        public IActionResult ProductDetails(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product selectedProductDetails = _iProductManager.GetById(id);

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

            ICollection <ProductPhoto> aProductPhotoList = _iProductPhotoManager.GetAll()
                                                           .Where(ph => ph.ProductId == id).ToList();
            ProductPhoto productFeaturedPhoto = aProductPhotoList
                                                .Where(ph => ph.Status == true && ph.Featured == true)
                                                .FirstOrDefault();

            ViewBag.ProductFeaturedPhotoName = productFeaturedPhoto == null ? "SlideShow/NoImageFound.png" : productFeaturedPhoto.Photo;
            ViewBag.ProductPhotoList         = aProductPhotoList;
            ViewBag.RelatedProduct           = _iProductManager.GetAll()
                                               .Where(p => p.CategoryId == selectedProductDetails.CategoryId &&
                                                      p.Id != selectedProductDetails.Id && p.Status == true).ToList();
            return(View(selectedProductDetails));
        }
Beispiel #8
0
        public ActionResult Edit(int pcid, int phid)
        {
            if (phid == 0)
            {
                return(Json(new
                {
                    Status = false,
                    Message = "圖檔未選取 !",
                }));
            }
            try
            {
                ProductPhoto pc = db.ProductPhotoes.Find(pcid);

                pc.PhotoID = phid;

                db.Entry(pc).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Status = false,
                    Message = ex.ToString(),
                }));
            }

            return(Json(new
            {
                Status = true,
                photoid = phid
            }));
        }
        public IActionResult Edit(ProductPhoto aProductPhotoInfo, IFormFile photo, string pto)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    string nameAndPath = Path.Combine(_iHostingEnvironment.WebRootPath
                                                      + "/productphotos", Path.GetFileName(photo.FileName));
                    photo.CopyToAsync(new FileStream(nameAndPath, FileMode.Create));
                    aProductPhotoInfo.Photo = "productphotos/" + photo.FileName;
                }

                if (photo == null)
                {
                    aProductPhotoInfo.Photo = pto;
                }

                bool isUpdate = _iProductPhotoManager.Update(aProductPhotoInfo);

                if (isUpdate)
                {
                    return(RedirectToAction("AllProductImage", "Product", new { id = aProductPhotoInfo.ProductId }));
                }
                else
                {
                    ViewBag.ErrorMessage = "Product Photo update has been failed! Try again.";
                    return(View(aProductPhotoInfo));
                }
            }

            return(RedirectToAction("Index", "Login"));
        }
Beispiel #10
0
        public async Task <IActionResult> UploadBlobProductImage([FromForm] FileUpload objFile)
        {
            try
            {
                if (objFile.files.Count > 0)
                {
                    var data = objFile.productPhotoData;

                    ProductPhoto itemContainer = JsonConvert.DeserializeObject <ProductPhoto>(data);
                    ProductPhoto item          = itemContainer;
                    item.productPhotoId = Guid.NewGuid();

                    var    files    = objFile.files;
                    string fileName = files[0].FileName;

                    string uri = await _azureBlobService.UploadAsyncProductPhoto(files, item.productVariantId.ToString());

                    item.PhotoURL = uri;
                    await ProductHandler.CreateProductPhotoMediaFile(item);

                    return(Ok("Image successfully uploaded"));
                }
                else
                {
                    return(StatusCode(505, "CS API Error: No files were recieved for upload, upload failed"));
                }
            }
            catch (Exception ex)
            {
                string errorMessage = handleCatch(ex);
                return(StatusCode(505, errorMessage));
            }
        }
Beispiel #11
0
        public async Task <IActionResult> Create(ProductPhotoCreateViewModel productPhotoCreateViewModel, IFormFile photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    string NameAndPath = Path.Combine(_iHostingEnvironment.WebRootPath + "/product_photo",
                                                      Path.GetFileName(photo.FileName));
                    await photo.CopyToAsync(new FileStream(NameAndPath, FileMode.Create));

                    productPhotoCreateViewModel.Photo = "product_photo/" + photo.FileName;
                }
                if (photo == null)
                {
                    productPhotoCreateViewModel.Photo = "product_photo/NoImageFound.jpg";
                }

                ProductPhoto createProductPhoto = _iMapper.Map <ProductPhoto>(productPhotoCreateViewModel);
                bool         isAdd = await _iProductPhotoManager.Create(createProductPhoto);

                if (isAdd == true)
                {
                    return(RedirectToAction("Index2", new { id = createProductPhoto.ProductId }));
                }

                return(ViewBag.ErrorMessage("Failed to save product photo"));
            }
            return(View(productPhotoCreateViewModel));
        }
Beispiel #12
0
 ///<summary>
 ///  Update the Typed ProductPhoto Entity with modified mock values.
 ///</summary>
 static public void UpdateMockInstance_Generated(TransactionManager tm, ProductPhoto mock)
 {
     mock.ThumbNailPhoto         = new byte[] { TestUtility.Instance.RandomByte() };
     mock.ThumbnailPhotoFileName = TestUtility.Instance.RandomString(24, false);;
     mock.LargePhoto             = new byte[] { TestUtility.Instance.RandomByte() };
     mock.LargePhotoFileName     = TestUtility.Instance.RandomString(24, false);;
     mock.ModifiedDate           = TestUtility.Instance.RandomDateTime();
 }
Beispiel #13
0
        ///<summary>
        ///  Update the Typed ProductPhoto Entity with modified mock values.
        ///</summary>
        static public void UpdateMockInstance(TransactionManager tm, ProductPhoto mock)
        {
            ProductPhotoTest.UpdateMockInstance_Generated(tm, mock);

            // make any alterations necessary
            // (i.e. for DB check constraints, special test cases, etc.)
            SetSpecialTestData(mock);
        }
        public ActionResult AddProduct(List <HttpPostedFileBase> Photo, AddProductViewModel product)
        {
            if (ModelState.IsValid)
            {
                AppDbContext  dbContext     = new AppDbContext();
                ProductModels productModels = new ProductModels();
                productModels.Price       = product.Price;
                productModels.Color       = product.Color;
                productModels.Storage     = product.Storage;
                productModels.Processor   = product.Processor;
                productModels.Memory      = product.Memory;
                productModels.Display     = product.Display;
                productModels.Details     = product.Details;
                productModels.BrandId     = product.BrandId;
                productModels.ModelId     = product.ModelId;
                productModels.CategoryId  = product.CategoryId;
                productModels.CreatedBy   = User.Identity.Name;
                productModels.CreatedDate = DateTime.Now;

                dbContext.addProduct(productModels);

                ModelModels model = dbContext.getModels.SingleOrDefault(m => m.Id == product.ModelId);

                productModels.Photos = new List <ProductPhoto>();
                foreach (var item in Photo)
                {
                    var fileName   = Path.GetFileName(item.FileName);
                    var path       = "/Public/Products/" + model.Name;
                    var photoUrl   = Server.MapPath(path);
                    var photoTitle = Path.GetFileNameWithoutExtension(item.FileName);
                    var uniqName   = Guid.NewGuid().ToString() + "_" + fileName;
                    if (!Directory.Exists(photoUrl))
                    {
                        Directory.CreateDirectory(photoUrl);
                    }

                    var          photoPath = Path.Combine(photoUrl, uniqName);
                    ProductPhoto photo     = new ProductPhoto
                    {
                        Path  = path,
                        Src   = photoPath,
                        Title = uniqName,

                        /*Get Id from the addProduct cmd.ExecuteScalar()*/
                        ProductId = productModels.Id
                    };
                    productModels.Photos.Add(photo);

                    item.SaveAs(photoPath);
                }

                dbContext.addProductPhoto(productModels.Photos);

                return(RedirectToAction("Products", "Product", new { id = product.ModelId }));
            }

            return(View());
        }
Beispiel #15
0
        private void LoadPhotos()
        {
            mainProductPhoto = product.GetMainPhoto();

            photoList = product.GetAllPhotosInSortOrder();

            rptPhotoList.DataSource = photoList;
            rptPhotoList.DataBind();
        }
Beispiel #16
0
        /// <summary>
        /// Adds the product.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="productModel">The product model.</param>
        /// <param name="productDescription">The product description.</param>
        /// <param name="productPhoto">The product photo.</param>
        /// <param name="culture">The culture.</param>
        /// <returns></returns>
        public async Task <Product> AddProduct(Product product, ProductModel productModel, ProductDescription productDescription,
                                               ProductPhoto productPhoto, Culture culture)
        {
            using (var transaction = await _context.Database.BeginTransactionAsync())
            {
                try
                {
                    // Adding new product description
                    var newProductDescription = await _context.ProductDescription.AddAsync(productDescription);

                    await _context.SaveChangesAsync();

                    // Adding new productmodel
                    var newProductModel = await _context.ProductModel.AddAsync(productModel);

                    await _context.SaveChangesAsync();

                    //// Adding relationship between new productmodel and new product description
                    await _context.ProductModelProductDescriptionCulture.AddAsync(new ProductModelProductDescriptionCulture()
                    {
                        ProductModelId       = newProductModel.Entity.ProductModelId,
                        ProductDescriptionId = newProductDescription.Entity.ProductDescriptionId,
                        CultureId            = culture.CultureId
                    });

                    await _context.SaveChangesAsync();

                    // Adding new product
                    product.ProductModelId = newProductModel.Entity.ProductModelId;
                    var newProduct = _context.Product.Add(product);
                    _context.SaveChanges();

                    // Adding new photos
                    var newProductPhoto = _context.ProductPhoto.Add(productPhoto);
                    _context.SaveChanges();

                    // Adding relationship between new product and new product photo
                    _context.ProductProductPhoto.Add(new ProductProductPhoto()
                    {
                        ProductId      = newProduct.Entity.ProductId,
                        ProductPhotoId = newProductPhoto.Entity.ProductPhotoId,
                    });
                    _context.SaveChanges();

                    // Commit transaction if all commands succeed, transaction will auto-rollback
                    // when disposed if either commands fails
                    transaction.Commit();

                    return(newProduct.Entity);
                }
                catch (Exception e)
                {
                    throw e.InnerException;
                }
            }
        }
Beispiel #17
0
        public ActionResult CreateProduct(Product product)
        {
            var imageList = Session["imageList"] as List <ImageModel>;

            if (ModelState.IsValid && imageList.Count != 0)
            {
                var newProduct = new Product
                {
                    ProductId     = Guid.NewGuid(),
                    CategoryId    = product.CategoryId,
                    CompanyId     = product.CompanyId,
                    Description   = product.Description,
                    Count         = product.Count,
                    Price         = product.Price,
                    Name          = product.Name,
                    PriceOfBuying = product.PriceOfBuying,
                    ProductNumber = product.ProductNumber,
                };
                _productRepository.Save(newProduct);
                foreach (var image in imageList)
                {
                    var photo = new ProductPhoto
                    {
                        ProductPhotoId = Guid.NewGuid(),
                        ProductId      = newProduct.ProductId
                    };

                    var filename      = String.Format("{0}_{1}", photo.ProductPhotoId, image.ImageName);
                    var thumbfilename = String.Format("{0}_thumb_{1}", photo.ProductPhotoId, image.ImageName);

                    var path      = Path.Combine(Server.MapPath("~/Content/images/admin/ProductImage"), filename);
                    var thumbpath = Path.Combine(Server.MapPath("~/Content/images/admin/ProductImage"), thumbfilename);

                    photo.Photo = filename;


                    Image imagePhotoVert = image.Image;
                    using (var imagePhoto = ImageResize.ScaleByPercent(imagePhotoVert, 70))
                    {
                        imagePhoto.Save(path);
                    }

                    var i = imageList.IndexOf(image);
                    if (i == 0)
                    {
                        using (var thumbimagePhoto = ImageResize.Crop(imagePhotoVert, 70, 70, AnchorPosition.Center))
                        {
                            thumbimagePhoto.Save(thumbpath);
                            photo.ThumbnailPhoto = thumbfilename;
                        }
                    }
                    _productPhotoRepository.Save(photo);
                }
            }
            return(View());
        }
Beispiel #18
0
        /// <summary>
        /// Check the foreign key dal methods.
        /// </summary>
        private void Step_10_FK_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                ProductPhoto entity = CreateMockInstance(tm);
                bool         result = DataRepository.ProductPhotoProvider.Insert(tm, entity);

                Assert.IsTrue(result, "Could Not Test FK, Insert Failed");
            }
        }
Beispiel #19
0
        public IHttpActionResult PostProductPhoto(int id, ProductPhoto photo)
        {
            photo.ProductId = id;

            db.ProductPhotos.Add(photo);

            db.SaveChanges();

            return(Ok(photo));
        }
Beispiel #20
0
        public IQueryable <Product> GetFeaturedProducts()
        {
            IList <Product>     products = new List <Product>();
            Product             product;
            ProductPhoto        prodPhoto;
            ProductProductPhoto prodProdPhoto;

            product      = new Product();
            product.Name = "Road-150 Red, 48";
            prodPhoto    = new ProductPhoto();
            prodPhoto.LargePhotoFileName = "~/Content/Images/SampleCycles/cycle1.gif";
            prodProdPhoto = new ProductProductPhoto()
            {
                ProductPhoto = prodPhoto
            };
            product.ProductProductPhotoes.Add(prodProdPhoto);
            products.Add(product);

            product      = new Product();
            product.Name = "Touring-2000 Blue, 60";
            prodPhoto    = new ProductPhoto();
            prodPhoto.LargePhotoFileName = "~/Content/Images/SampleCycles/cycle2.gif";
            prodProdPhoto = new ProductProductPhoto()
            {
                ProductPhoto = prodPhoto
            };
            product.ProductProductPhotoes.Add(prodProdPhoto);
            products.Add(product);

            product      = new Product();
            product.Name = "Mountain-100 Black, 42";
            prodPhoto    = new ProductPhoto();
            prodPhoto.LargePhotoFileName = "~/Content/Images/SampleCycles/cycle3.gif";
            prodProdPhoto = new ProductProductPhoto()
            {
                ProductPhoto = prodPhoto
            };
            product.ProductProductPhotoes.Add(prodProdPhoto);
            products.Add(product);

            product      = new Product();
            product.Name = "Road-350-W Yellow, 44";
            prodPhoto    = new ProductPhoto();
            prodPhoto.LargePhotoFileName = "~/Content/Images/SampleCycles/cycle4.jpg";
            prodProdPhoto = new ProductProductPhoto()
            {
                ProductPhoto = prodPhoto
            };
            product.ProductProductPhotoes.Add(prodProdPhoto);
            products.Add(product);


            return(products.AsQueryable <Product>());
        }
        public async Task Create(ProductPhotoDto dto)
        {
            var productPhoto = new ProductPhoto
            {
                Url         = dto.Url,
                ProductId   = dto.ProductId,
                ErasedState = false
            };

            await _productPhotoRepository.Create(productPhoto);
        }
Beispiel #22
0
        /// <summary>
        /// Test methods exposed by the EntityHelper class.
        /// </summary>
        private void Step_20_TestEntityHelper_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                mock = CreateMockInstance(tm);

                ProductPhoto entity = mock.Copy() as ProductPhoto;
                entity = (ProductPhoto)mock.Clone();
                Assert.IsTrue(ProductPhoto.ValueEquals(entity, mock), "Clone is not working");
            }
        }
        public async Task <IActionResult> Create([Bind("Photo_id,Source,Alt,Product_id")] ProductPhoto productPhoto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productPhoto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Product_id"] = new SelectList(_context.Products, "Product_id", "Description", productPhoto.Product_id);
            return(View(productPhoto));
        }
Beispiel #24
0
        public HttpResponseMessage AddProduct()
        {
            var    httpRequest = HttpContext.Current.Request;
            string imageName   = "";

            try
            {
                var postedFile = httpRequest.Files["Image"];
                imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(postedFile.FileName.Length).ToArray()).Replace(" ", "-");
                imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
                var FilePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName);
                postedFile.SaveAs(FilePath);
            }
            catch (Exception err)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Image was not saved (" + err.Message + ")"));
            }

            try
            {
                string  name   = httpRequest["Name"];
                Product verify = db.Products.Where(zz => zz.Name == name).FirstOrDefault();
                if (verify == null)
                {
                    Product newProd = new Product();

                    newProd.Name           = httpRequest["Name"];
                    newProd.Description    = httpRequest["Description"];
                    newProd.CategoryID     = Convert.ToInt32(httpRequest["CategoryID"]);
                    newProd.Price          = Convert.ToDecimal(httpRequest["Price"]);
                    newProd.SupplierID     = Convert.ToInt32(httpRequest["SupplierID"]);
                    newProd.QuantityOnHand = Convert.ToInt32(httpRequest["QuantityOnHand"]);

                    db.Products.Add(newProd);
                    db.SaveChanges();
                    db.Entry(newProd).GetDatabaseValues();
                    int ProdID = newProd.ProductID;

                    ProductPhoto photo = new ProductPhoto();
                    photo.ProductID = ProdID;
                    photo.Photo     = imageName;

                    db.ProductPhotoes.Add(photo);
                    db.SaveChanges();
                }
            }
            catch
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Product details are invalid"));
            }

            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Beispiel #25
0
        ///<summary>
        ///  Returns a Typed ProductPhoto Entity with mock values.
        ///</summary>
        static public ProductPhoto CreateMockInstance(TransactionManager tm)
        {
            // get the default mock instance
            ProductPhoto mock = ProductPhotoTest.CreateMockInstance_Generated(tm);

            // make any alterations necessary
            // (i.e. for DB check constraints, special test cases, etc.)
            SetSpecialTestData(mock);

            // return the modified object
            return(mock);
        }
        /// <summary>
        /// Converts the webservice response to the BusinessObject we defined in Ilc.BusinessObjects.AdventureWorks
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private ProductPhoto ReadPhoto(Dictionary <string, string> reader)
        {
            var p = new ProductPhoto
            {
                Id = int.Parse(reader["Id"]),
                LargePhotoFileName = reader["LargePhotoFileName"],
                ModifiedDate       = DateTime.Parse(reader["ModifiedDate"]),
            };

            p.LargePhotoB64 = reader["LargePhotoB64"];
            return(p);
        }
Beispiel #27
0
        public async Task <IActionResult> Create([Bind("ProductPhotoId,ProductId,PhotoFilename")] ProductPhoto productPhoto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productPhoto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", productPhoto.ProductId);
            return(View(productPhoto));
        }
        // PUT api/awbuildversion/5
        public void Put(ProductPhoto value)
        {
            var GetActionType = Request.Headers.Where(x => x.Key.Equals("ActionType")).FirstOrDefault();

            if (GetActionType.Key != null)
            {
                if (GetActionType.Value.ToList()[0].Equals("DELETE"))
                    adventureWorks_BC.ProductPhotoDelete(value);
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                    adventureWorks_BC.ProductPhotoUpdate(value);
            }
        }
Beispiel #29
0
        public async Task <Guid> UploadPhotoAsync(ProductRequestModels.UploadPhoto request)
        {
            var photo = new ProductPhoto()
            {
                ProductId = request.ProductId,
                Url       = request.Url
            };

            _productRepo.UploadPhoto(photo);
            await _productRepo.UnitOfWork.SaveChangesAsync();

            return(photo.ProductId);
        }
Beispiel #30
0
        /// <summary>
        /// Serialize the mock ProductPhoto entity into a temporary file.
        /// </summary>
        private void Step_06_SerializeEntity_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                mock = CreateMockInstance(tm);
                string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_ProductPhoto.xml");

                EntityHelper.SerializeXml(mock, fileName);
                Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock not found");

                System.Console.WriteLine("mock correctly serialized to a temporary file.");
            }
        }
Beispiel #31
0
        public void DeleteTest()
        {
            ProductPhotoRepository repository = new ProductPhotoRepository();
            ProductPhoto           model      = new ProductPhoto
            {
                PhotoID = 2
            };

            repository.Delete(model);
            var photos = repository.FindById(1);

            Assert.IsTrue(photos.Count() > 0);
        }
Beispiel #32
0
 public void AddToProductPhoto(ProductPhoto productPhoto)
 {
     base.AddObject("ProductPhoto", productPhoto);
 }
Beispiel #33
0
 public static ProductPhoto CreateProductPhoto(int productId, int photoId)
 {
     ProductPhoto productPhoto = new ProductPhoto();
     productPhoto.ProductId = productId;
     productPhoto.PhotoId = photoId;
     return productPhoto;
 }
 partial void DeleteProductPhoto(ProductPhoto instance);
 partial void UpdateProductPhoto(ProductPhoto instance);
 // POST api/awbuildversion
 public void Post(ProductPhoto value)
 {
     adventureWorks_BC.ProductPhotoAdd(value);
 }
 partial void InsertProductPhoto(ProductPhoto instance);
 /// <summary>
 /// Create a new ProductPhoto object.
 /// </summary>
 /// <param name="productPhotoID">Initial value of ProductPhotoID.</param>
 /// <param name="modifiedDate">Initial value of ModifiedDate.</param>
 public static ProductPhoto CreateProductPhoto(int productPhotoID, global::System.DateTime modifiedDate)
 {
     ProductPhoto productPhoto = new ProductPhoto();
     productPhoto.ProductPhotoID = productPhotoID;
     productPhoto.ModifiedDate = modifiedDate;
     return productPhoto;
 }