예제 #1
0
        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"));
        }
예제 #2
0
        // 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);
        }
예제 #3
0
        // 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);
        }
예제 #4
0
        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")));
        }
예제 #5
0
 //insert carimg
 public void InsertCarImg(CarImgModel carImgModel)
 {
     carImgModel.ID_CarImg = Guid.NewGuid();
     dbContext.CarImgs.InsertOnSubmit(MapModelsToDbObject(carImgModel));
     dbContext.SubmitChanges();
 }
예제 #6
0
        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"));
            }
        }
예제 #7
0
        // GET: CarImg/Create
        public ActionResult InsertImg()
        {
            CarImgModel carImgModel = new CarImgModel();

            return(View(carImgModel));
        }