public Dictionary <int, bool> UploadImage([Bind(Include = "Files, IsDisplayPosition")] ProductDetailModel productDetailModel) { Image image = new Image(); Dictionary <int, bool> lstImageID = new Dictionary <int, bool>(); int position = 1; foreach (HttpPostedFileBase file in productDetailModel.Files) { string fname = FileMng.UploadFile(file, "/Images"); image.path = "Images\\" + fname; image.IconID = _dbContext.Icon.Max(i => i.IconID); _dbContext.Image.Add(image); _dbContext.SaveChanges(); if (position == productDetailModel.IsDisplayPosition) { lstImageID.Add(_dbContext.Image.Max(i => i.ImageID), true); //set us display } else { lstImageID.Add(_dbContext.Image.Max(i => i.ImageID), false); } position++; } return(lstImageID); }
private void RemoveOldImage([Bind(Include = "FileToRemove")] ProductDetailModel productDetailModel) //remove old image from directory { foreach (var item in productDetailModel.FileToRemove.Where(f => f != 0).ToArray()) { Image image = _dbContext.Image.Find(item); FileMng.RemoveFile(System.Web.HttpContext.Current.Server.MapPath("~\\" + image.path)); } }
private void ChangeIconAndDirectoryPath([Bind(Include = "IconID, IconFile")] ProductDetailModel productDetailModel) { Icon icon = new Icon(); HttpPostedFileBase file = productDetailModel.IconFile; string path = "Images\\AddImageIcon\\" + FileMng.UploadFile(file, "/Images/AddImageIcon"); icon.IconID = productDetailModel.IconID; icon.icon1 = path; //new path _dbContext.Entry(icon).State = EntityState.Modified; _dbContext.SaveChanges(); }
private void ChangeImage([Bind(Include = "Files, FileToRemove")] ProductDetailModel productDetailModel) { int[] arrImgID = productDetailModel.FileToRemove.Where(f => f != 0).ToArray(); int indx = 0; foreach (HttpPostedFileBase file in productDetailModel.Files) { Image image = _dbContext.Image.Find(arrImgID[indx++]); image.path = "Images\\" + FileMng.UploadFile(file, "/Images"); _dbContext.SaveChanges(); } }
static void Main(string[] args) { Console.Write("\n C# Client AutoTest for COM Project"); Console.Write("\n ===========================\n"); string reg = "(S)(.*)"; string regforname = "(T)(.*)"; string filepathDir = "../../../ATLProject2"; Console.WriteLine("Demostrating 1st COM, FileMng. This COM object should receive a string path and a regular expression, and return a string list of the matched filename/filepath."); Console.WriteLine("Finding regular expression '" + regforname + "' for filenames under " + filepathDir); FileMng fm = new FileMng(); object result = new object(); fm.GetFileList(filepathDir, regforname, ref result); Array ct = (Array)result; string[] content = new string[ct.Length]; ct.CopyTo(content, 0); Console.WriteLine(content.Length + " files are found:"); for (int i = 0; i < content.Length; i++) { Console.WriteLine("File " + i + ": " + content[i]); } Console.WriteLine("Press any key to see result of 2nd COM"); Console.ReadLine(); Console.WriteLine("Demostrating 2nd COM, TextSearch. This COM object should receive a string path and a regular expression, and return the line numbers that matches."); Console.WriteLine("Finding regular expression '" + reg + "' for lines under " + filepathDir); TextSearcher ts = new TextSearcher(); foreach (string i in content) { string reply = ""; ts.FindLines(i, reg, ref reply); if (reply != "") { Console.WriteLine(reply); } } Console.WriteLine("Press any key to exit"); Console.ReadLine(); }
public void CreateProductDetail([Bind] ProductDetailModel productDetailModel) { //upload icon path productDetailModel.IconPath = "Images\\AddImageIcon\\" + FileMng.UploadFile(productDetailModel.IconFile, "/Images/AddImageIcon"); _productDetailRepository.CreateNewIcon(new ProductDetailModel() { IconPath = productDetailModel.IconPath }); //create product size and color List <int> ListingProductDetailID = _productDetailRepository.CreateProductSizeAndColor(new ProductDetailModel { ProductID = productDetailModel.ProductID, ColorID = productDetailModel.ColorID, SizeID = productDetailModel.SizeID }); //upload images Dictionary <int, bool> ListingImageID = _productDetailRepository.UploadImage(new ProductDetailModel { Files = productDetailModel.Files, IsDisplayPosition = productDetailModel.IsDisplayPosition }); _productDetailRepository.CreateProductDetail(productDetailModel, ListingProductDetailID, ListingImageID); _productDetailRepository.CreateDisplayDetail(new ProductDetailModel { ProductID = productDetailModel.ProductID }, ListingImageID.Where(i => i.Value == true).FirstOrDefault().Key); }
public void ChangeImageIcon([Bind(Include = "IconID, IconPath, IconFile")] ProductDetailModel productDetailModel) { FileMng.RemoveFile(System.Web.HttpContext.Current.Server.MapPath("~\\" + productDetailModel.IconPath)); ChangeIconAndDirectoryPath(productDetailModel); //update the icon inside the directory and its path to the database }