public void EditModel(VehicleModelVM VehicleModelVM) { // db.Entry(Mapper.Map<VehicleModel>(VehicleModelVM)).State = EntityState.Modified; // db.SaveChanges(); db.Set <VehicleModel>().AddOrUpdate(Mapper.Map <VehicleModel>(VehicleModelVM)); db.SaveChanges(); }
public IActionResult Create(VehicleModelVM model) { try { var modelForCreation = mapper.Map <Model>(model); if (ModelState.IsValid) { modelService.Create(modelForCreation); return(RedirectToAction("Detail", "Model", new { id = modelForCreation.Id })); } else { var createModel = new CreateModel { Abrv = model.Abrv, MakeId = model.MakeId, DetailMakeName = model.DetailMakeName }; return(View(createModel)); } } catch (Exception) { return(BadRequest()); } }
public async Task <IHttpActionResult> CreateVehicleModelAsync(VehicleModelVM vehicleModel) { if (ModelState.IsValid) { await _vehicleModelService.AddVehicleModelAsync(Mapper.Map <VehicleModel>(vehicleModel)); } return(Ok(vehicleModel)); }
public ActionResult Edit([Bind(Include = "Id,IdVehicleMake,Name,Abrv")] VehicleModelVM vehicleModelVM) { if (ModelState.IsValid) { VehicleService.GetInstance().EditModel(vehicleModelVM); return(RedirectToAction("Index")); } return(View(vehicleModelVM)); }
public IActionResult Update(VehicleModelVM model) { try { modelService.Update(mapper.Map <Model>(model)); return(RedirectToAction("Detail", "Model", new { id = model.Id })); } catch (Exception) { return(BadRequest()); } }
public async Task <IHttpActionResult> DeleteVehicleModelAsync(int?id) { VehicleModelVM vehicleModelVM = Mapper.Map <VehicleModelVM>(await _vehicleModelService.GetVehicleModelAsync((int)id)); if (vehicleModelVM == null) { return(NotFound()); } await _vehicleModelService.DeleteVehicleModelAsync((int)id); return(Ok(vehicleModelVM)); }
/// <summary> /// Post method, /// api/VehicleModel /// </summary> /// <param name="VM">View Model, type of VehicleModelVM</param> public async Task <IHttpActionResult> Post([FromBody] VehicleModelVM VM) { try { await service.AddVehicleModelAsync(AutoMapper.Mapper.Map <IVehicleModel>(VM)); return(Ok()); } catch (DataException) { ModelState.AddModelError("", "Something went wrong can't create VehicleModel"); return(InternalServerError()); } }
public IActionResult Add(VehicleModelVM vehicleModel) { if (ModelState.IsValid) { var vh = mapper.Map <project.service.Models.VehicleModel>(vehicleModel); _vehicleModel.Add(vh); this.StatusCode(200); } else { this.StatusCode(400); } return(RedirectToAction("index")); }
public async Task <IHttpActionResult> UpdateVehicleModelAsync(int id, VehicleModelVM vehicleModel) { if (ModelState.IsValid) { await _vehicleModelService.UpdateVehicleModelAsync(Mapper.Map <VehicleModel>(vehicleModel)); } if (id != vehicleModel.Id) { return(BadRequest()); } if (vehicleModel == null) { return(NotFound()); } return(Ok(vehicleModel)); }
public ActionResult Edit(VehicleModelVM obj) { if (ModelState.IsValid) { string str = repository.EditModel(obj); if (str == "Ok") { return(RedirectToAction("Index")); } else { return(View()); } } else { return(View()); } }
public async Task <IHttpActionResult> Put(int?id, [FromBody] VehicleModelVM VM) { try { if (id == null) { return(BadRequest()); } var success = await service.UpdateVehicleModelAsync(AutoMapper.Mapper.Map <IVehicleModel>(VM)); if (!success) { return(BadRequest()); } return(Ok()); } catch { ModelState.AddModelError("", "Something went wrong can't update VehicleModel"); return(InternalServerError()); } }
public string EditModel(VehicleModelVM item) { string result = string.Empty; try { var m = dbContext.Models.FirstOrDefault(x => x.Id == item.Id); if (m != null) { m.Name = item.Name; m.MakeId = item.MakeId; m.Abrv = item.Abrv; dbContext.SaveChanges(); result = "Ok"; } } catch (Exception ex) { result = ex.Message; } return(result); }
public string AddModel(VehicleModelVM item) { string result = string.Empty; if (item == null) { throw new ArgumentNullException("item"); } try { Mapper.CreateMap <VehicleModelVM, VehicleModel>(); var m = Mapper.Map <VehicleModelVM, VehicleModel>(item); dbContext.Models.Add(m); dbContext.SaveChanges(); result = "Ok"; } catch (Exception ex) { result = ex.Message; } return(result); }
/* public IPagedList<VehicleMakeVM> FindMakeName(string search, int? page, string sortBy) * { * * * return * * } * public IPagedList<VehicleMakeVM> FindMakeAbrv(string search, int? page) * { * return * * }*/ //Sad radim za model public void CreateModel(VehicleModelVM VehicleModelVM) { VehicleModelVM.Id = Guid.NewGuid(); db.VehicleModels.Add(Mapper.Map <VehicleModel>(VehicleModelVM)); db.SaveChanges(); }