// GET: Anunt/Edit/5 public ActionResult EditAnunt(Guid ID) { AnuntModel anuntModel = anuntRepository.GetAnuntByID(ID); anuntModel.ID_Anunt = ID; return(View("ListaAnunturi", anuntModel)); }
//insert (nu renutrneaza nimic folosim void) public void InsertAnunt(AnuntModel anuntModel) { //generare id guid anuntModel.ID_Anunt = Guid.NewGuid(); // add to orm layer dbContext.Anunts.InsertOnSubmit(MapModelToDbObject(anuntModel)); //commit to db dbContext.SubmitChanges(); }
//update (nu renutrneaza nimic folosim void) public void UpdateAnunt(AnuntModel anuntModel) { Models.DbObjects.Anunt existingAnunt = dbContext.Anunts.FirstOrDefault(x => x.ID_Anunt == anuntModel.ID_Anunt); if (existingAnunt != null) { //map update values si pastram referintele orm existingAnunt.ID_Anunt = anuntModel.ID_Anunt; //existingAnunt.ID_User = anuntModel.ID_User; existingAnunt.ID_Model = anuntModel.ID_Model; existingAnunt.ID_Caracteristica = anuntModel.ID_Caracteristica; existingAnunt.KM = anuntModel.KM; existingAnunt.AnFabricatie = anuntModel.AnFabricatie; existingAnunt.Descriere = anuntModel.Descriere; existingAnunt.DescriereScurta = anuntModel.DescriereScurta; existingAnunt.Pret = anuntModel.Pret; dbContext.SubmitChanges(); } }
// map Model to ORM - mapper method private Anunt MapModelToDbObject(AnuntModel anuntModel) { Anunt dbAnuntModel = new Anunt(); if (anuntModel != null) { dbAnuntModel.ID_Anunt = anuntModel.ID_Anunt; dbAnuntModel.ID_Caracteristica = anuntModel.ID_Caracteristica; dbAnuntModel.ID_TipCaracteristica = anuntModel.ID_TipCaracteristica; dbAnuntModel.ID_User = anuntModel.ID_User; dbAnuntModel.ID_Model = anuntModel.ID_Model; dbAnuntModel.ID_Marca = anuntModel.ID_Marca; dbAnuntModel.KM = anuntModel.KM; dbAnuntModel.Descriere = anuntModel.Descriere; dbAnuntModel.DescriereScurta = anuntModel.DescriereScurta; dbAnuntModel.Pret = anuntModel.Pret; dbAnuntModel.AnFabricatie = anuntModel.AnFabricatie; return(dbAnuntModel); } return(null); }
public IHttpActionResult Publish(AnuntModel model) { if (ModelState.IsValid) { var dto = new AnuntDto() { Content = model.Content, Subject = model.Subject, Role = model.Role }; var anuntId = _anuntService.AddAnunt(dto); var pushInfo = new PushInfo() { Id = anuntId, Subject = dto.Subject }; _signalRHelper.NotifyAnunturiForRole(pushInfo, dto.Role); return(Ok()); } return(BadRequest()); }
// map ORM to Model - mapper method private AnuntModel MapDbObjectToModel(Anunt dbAnunt) { AnuntModel anuntModel = new AnuntModel(); if (dbAnunt != null) { anuntModel.ID_Anunt = dbAnunt.ID_Anunt; anuntModel.ID_User = dbAnunt.ID_User; anuntModel.ID_Model = dbAnunt.ID_Model; anuntModel.ID_Marca = dbAnunt.ID_Marca; anuntModel.ID_TipCaracteristica = dbAnunt.ID_TipCaracteristica; anuntModel.ID_Caracteristica = dbAnunt.ID_Caracteristica; anuntModel.KM = dbAnunt.KM; anuntModel.AnFabricatie = dbAnunt.AnFabricatie; anuntModel.Descriere = dbAnunt.Descriere; anuntModel.DescriereScurta = dbAnunt.DescriereScurta; anuntModel.Pret = dbAnunt.Pret; return(anuntModel); } return(null); }
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")); } }