public ActionResult InsertImg(CarImgModel model) { CarImgModel carImgModel = new CarImgModel(); //carImgModel.SomeFile = model.SomeFile; carImgModel.TitleFile = model.TitleFile; carImgModel.ExtensionFile = model.ExtensionFile; carImgModel.ContentFile = model.ContentFile; carImgModel.ID_Anunt = model.ID_Anunt; carImgModel.ID_CarImg = model.ID_CarImg; carImgRepository.InsertCarImg(carImgModel); return(RedirectToAction("CarImgList")); }
// map Model to ORM private CarImg MapModelsToDbObject(CarImgModel carImgModel) { CarImg dbCarImgModel = new CarImg(); if (carImgModel != null) { dbCarImgModel.ID_CarImg = carImgModel.ID_CarImg; dbCarImgModel.ID_Anunt = carImgModel.ID_Anunt; dbCarImgModel.ContentFile = carImgModel.ContentFile; dbCarImgModel.ExtensionFile = carImgModel.ExtensionFile; dbCarImgModel.TitleFile = carImgModel.TitleFile; return(dbCarImgModel); } return(null); }
// map orm to model - mapper method private CarImgModel MapDbObjectToModel(CarImg dbCarImg) { CarImgModel carImgModel = new CarImgModel(); if (dbCarImg != null) { //carImgModel.SomeFile = dbCarImg.SomeFile; carImgModel.ID_CarImg = dbCarImg.ID_CarImg; carImgModel.ID_Anunt = dbCarImg.ID_Anunt; carImgModel.ContentFile = dbCarImg.ContentFile.ToArray(); carImgModel.ExtensionFile = dbCarImg.ExtensionFile; carImgModel.TitleFile = dbCarImg.TitleFile; return(carImgModel); } return(null); }
public ActionResult AnuntMultipleFile(string ID) { try { if (ID != "") { AUTOsrs.Repository.CarImgRepository imgRepository = new AUTOsrs.Repository.CarImgRepository(); CarImgModel carImgModel = imgRepository.GetCarImgById(new Guid(ID)); if (carImgModel != null) { byte[] contentFile = carImgModel.ContentFile; return(File(contentFile, GetContentType(carImgModel.ExtensionFile))); } } } catch { } //not Found Image return(File(notFoundImage, GetContentType(".jpg"))); }
//insert carimg public void InsertCarImg(CarImgModel carImgModel) { carImgModel.ID_CarImg = Guid.NewGuid(); dbContext.CarImgs.InsertOnSubmit(MapModelsToDbObject(carImgModel)); dbContext.SubmitChanges(); }
public ActionResult CreateAnunt(AnuntGeneralViewModel model) { if (model.ID_Anunt != Guid.Empty) { AnuntModel anuntModel = new AnuntModel(); anuntModel.ID_Anunt = model.ID_Anunt; anuntModel.ID_Caracteristica = model.ID_Caracteristica; anuntModel.ID_Model = model.ID_Model; anuntModel.ID_Marca = model.ID_Marca; anuntModel.ID_TipCaracteristica = model.ID_TipCaracteristica; anuntModel.KM = model.KM; anuntModel.Pret = model.Pret; anuntModel.Descriere = model.Descriere; anuntModel.AnFabricatie = model.AnFabricatie; anuntRepository.UpdateAnunt(anuntModel); return(RedirectToAction("IndexAnunt")); } else { if (model != null) { AnuntModel anuntModel = new AnuntModel(); anuntModel.ImagePath = model.ImagePath; anuntModel.ID_Caracteristica = model.ID_Caracteristica; anuntModel.ID_Model = model.ID_Model; anuntModel.ID_Marca = model.ID_Marca; anuntModel.ID_TipCaracteristica = model.ID_TipCaracteristica; anuntModel.KM = model.KM; anuntModel.Pret = model.Pret; anuntModel.Descriere = model.Descriere; anuntModel.DescriereScurta = model.DescriereScurta; anuntModel.AnFabricatie = model.AnFabricatie; anuntRepository.InsertAnunt(anuntModel); //foreach CarImgModel carImgModel = new CarImgModel(); if (model.ImageFile != null) { //Use Namespace called : System.IO carImgModel.TitleFile = Path.GetFileNameWithoutExtension(model.ImageFile.FileName); //To Get File Extension carImgModel.ExtensionFile = Path.GetExtension(model.ImageFile.FileName); //To copy and save file into server. using (var memoryStream = new MemoryStream()) { model.ImageFile.InputStream.CopyTo(memoryStream); carImgModel.ContentFile = memoryStream.ToArray(); } } carImgModel.ID_Anunt = anuntModel.ID_Anunt; imgRepository.InsertCarImg(carImgModel); } return(RedirectToAction("IndexAnunt")); } }
// GET: CarImg/Create public ActionResult InsertImg() { CarImgModel carImgModel = new CarImgModel(); return(View(carImgModel)); }