public ActionResult EditPost(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IVehicleMake MakerToUpdate = Service.FindMaker(id); if (TryUpdateModel(MakerToUpdate, "", new string[] { "MakerName", "MakerDescription" })) { try { Service.UpdateMaker(MakerToUpdate); return(RedirectToAction("Index")); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } return(View(AutoMapper.Mapper.Map <MakerViewModel>(MakerToUpdate))); }
public async Task UpdateMake(IVehicleMake vehicle) { VehicleMake update = mapper.Map <VehicleMake>(vehicle); context.VehicleMakes.Update(update); await context.SaveChangesAsync(); }
public async virtual Task <IVehicleMake> AddAsync(IVehicleMake make) { // make that is returned after creating. var returnedMake = await Repository.AddAsync(Mapper.Map <VehicleMake>(make)); return(Mapper.Map <IVehicleMake>(returnedMake)); }
public async Task InsertMake(IVehicleMake vehicle) { VehicleMake create = mapper.Map <VehicleMake>(vehicle); context.VehicleMakes.Add(create); await context.SaveChangesAsync(); }
public async Task <IVehicleMake> UpdateVehicleMakerAsync(int id, IVehicleMake changedMaker) { var maker = await UnitOfWork.VehicleMakeRepository.Update(id, Mapper.Map <Vehicle.DAL.Entities.VehicleMakeEntity>(changedMaker)); await UnitOfWork.CommitAsync(); return(Mapper.Map <IVehicleMake>(maker)); }
public async Task <IVehicleMake> FindById(object id) { VehicleMakeEntityModel vehicleEntity = await _genericRepository.FindById(id); IVehicleMake vehicleMake = iMapper.Map <VehicleMake>(vehicleEntity); return(vehicleMake); }
public async Task <IVehicleMake> AddMakeAsync(IVehicleMake make) { var createdMaker = await unitOfWork.Makers.AddAsync(make); await unitOfWork.CommitAsync(); return(createdMaker); }
public async Task <IVehicleMake> FindById(object id) { VehicleMakeEntity vehicleEntity = await dbSet.FindAsync(id); IVehicleMake vehicleMake = _mapper.Map <VehicleMake>(vehicleEntity); return(vehicleMake); }
public async Task <IVehicleMake> AddVehicleMakerAsync(IVehicleMake newMaker) { await UnitOfWork.VehicleMakeRepository.Add(Mapper.Map <Vehicle.DAL.Entities.VehicleMakeEntity>(newMaker)); await UnitOfWork.CommitAsync(); return(newMaker); }
public async Task <ActionResult> Edit(int id) { IVehicleMake VehicleMake = await Service.GetAsync(id); if (VehicleMake == null) { return(HttpNotFound()); } return(View(VehicleMake)); }
public async Task <VehicleMake> CreateMake(IVehicleMake makeToCreate) { var newMakeToCreateEntity = mapper.Map <VehicleMakeEntity>(makeToCreate); var makeToCreateEntity = await Create(newMakeToCreateEntity); await SaveAsync(); var createdMake = mapper.Map <VehicleMake>(makeToCreateEntity); return(createdMake); }
public async Task <VehicleMake> UpdateMake(IVehicleMake makeUpdates) { var makeEntityUpdates = mapper.Map <VehicleMakeEntity>(makeUpdates); var makeToUpdateEntity = await Update(makeEntityUpdates); await SaveAsync(); var updatedMake = mapper.Map <VehicleMake>(makeToUpdateEntity); return(updatedMake); }
public async Task <IVehicleMake> AddVehicleMakeAsync(IVehicleMake vehicleMake) { if (vehicleMake != null) { var vehicleMakeEntity = Mapper.Map <VehicleMakeEntity>(vehicleMake); vehicleMakeEntity.Abrv = vehicleMakeEntity.Name.ToLower(); await Context.VehicleMakes.AddAsync(vehicleMakeEntity); await Context.SaveChangesAsync(); } return(vehicleMake); }
public async Task <IHttpActionResult> GetVehicleMakeByID(int?id) { IVehicleMake vehicleMake = await _vehicleMakeService.GetVehicleMakeByID(id); if (vehicleMake == null) { return(NotFound()); } VehicleMakeViewModel vehicleMakeViewModels = _mapper.Map <VehicleMakeViewModel>(vehicleMake); return(Ok(vehicleMakeViewModels)); }
public async Task <bool> Create(IVehicleMake vehicleMake) { try { VehicleMakeEntity entity = _mapper.Map <VehicleMakeEntity>(vehicleMake); dbSet.Add(entity); return(true); } catch { return(false); } }
public void Delete(IVehicleMake entityToDelete) { try { VehicleMakeEntityModel vehicleEntity = iMapper.Map <VehicleMakeEntityModel>(entityToDelete); _genericRepository.Delete(vehicleEntity); } catch (Exception) { throw; } }
/// <summary> /// Update method, /// updates/edits VehicleMake. /// </summary> /// <param name="entity">Model, type of IVehicleMake.</param> /// <returns>Returns boolean to controller, so controller knows if VeickeMake was update or not.</returns> public async Task <Boolean> UpdateVehicleMakeAsync(IVehicleMake entity) { if (repository.GetVehicleMakeAsync(entity.Id) != null) { await repository.UpdateVehicleMakeAsync(entity); return(true); } else { return(false); } }
public async Task <IHttpActionResult> DeleteVehicleMake(int id) { IVehicleMake vehicleMake = await _vehicleService.FindVehicleMake(id); if (vehicleMake == null) { return(NotFound()); } await _vehicleService.DeleteVehicleMake(id); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetVehicleMake(int id) { IVehicleMake vehicleMake = await _vehicleService.FindVehicleMake(id); if (vehicleMake == null) { return(NotFound()); } VehicleMakeViewModel vehicleMakeViewModel = iMapper.Map <VehicleMakeViewModel>(vehicleMake); return(Ok(vehicleMakeViewModel)); }
public async Task <bool> Create(IVehicleMake vehicleMake) { try { VehicleMakeEntityModel entity = iMapper.Map <VehicleMakeEntityModel>(vehicleMake); await _genericRepository.Create(entity); return(true); } catch { return(false); } }
public async Task <IVehicleMake> UpdateVehicleMakeAsync(IVehicleMake vehicleMake) { if (vehicleMake != null) { var vehicleMakeEntity = Mapper.Map <VehicleMakeEntity>(vehicleMake); vehicleMakeEntity.DateModified = DateTime.UtcNow; var vehicleMakeEntityEntry = Context.VehicleMakes.Attach(vehicleMakeEntity); vehicleMakeEntityEntry.State = EntityState.Modified; await Context.SaveChangesAsync(); return(vehicleMake); } return(null); }
public void SaveChanges(IVehicleMake vehicleMake) { if (vehicleMake.Id == 0) { context.Add(mapper.Map <VehicleMake>(vehicleMake)); context.SaveChanges(); } else { var vehicle = context.VehicleMakers.Attach(mapper.Map <VehicleMake>(vehicleMake)); vehicle.State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IVehicleMake maker = Service.FindMaker(id); if (maker == null) { return(HttpNotFound()); } return(View(AutoMapper.Mapper.Map <MakerViewModel>(maker))); }
public MakeController( IMakeServicesAsync makeService, IModelServicesAsync modelService, IFilteringFactory filteringFactory, ISortingFactory sortingFactory, IPagingFactory pagingFactory, IVehicleMake vehicleMake) { _makeService = makeService ?? throw new ArgumentNullException(nameof(IMakeServicesAsync)); _modelService = modelService ?? throw new ArgumentNullException(nameof(IModelServicesAsync)); _filteringFactory = filteringFactory ?? throw new ArgumentNullException(nameof(IFilteringFactory)); _sortingFactory = sortingFactory ?? throw new ArgumentNullException(nameof(ISortingFactory)); _pagingFactory = pagingFactory ?? throw new ArgumentNullException(nameof(IPagingFactory)); _vehicleMake = vehicleMake ?? throw new ArgumentNullException(nameof(IVehicleMake)); }
public async Task <bool> CreateVehicleMake(IVehicleMake vehicleMake) { try { await _vehicleMakeRepository.Create(vehicleMake); await _unitOfWork.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <bool> EditVehicleMake(IVehicleMake vehicleMake) { try { await _repository.Edit(vehicleMake); await uow.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <bool> Edit(IVehicleMake entity) { try { VehicleMakeEntityModel vehicleEntity = iMapper.Map <VehicleMakeEntityModel>(entity); await _genericRepository.Edit(vehicleEntity); return(true); } catch { return(false); } }
public async Task <bool> Edit(IVehicleMake entity) { try { VehicleMakeEntity vehicleEntity = _mapper.Map <VehicleMakeEntity>(entity); DbEntityEntry dbEntityEntry = _context.Entry(vehicleEntity); if (dbEntityEntry.State == EntityState.Detached) { dbSet.Attach(vehicleEntity); } dbEntityEntry.State = EntityState.Modified; return(true); } catch { return(false); } }
public ActionResult Delete(int?id, bool?saveChangesError = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator."; } IVehicleMake maker = Service.FindMaker(id); if (maker == null) { return(HttpNotFound()); } return(View(AutoMapper.Mapper.Map <MakerViewModel>(maker))); }
public async Task <int> AddAsync(IVehicleMake entity) { if (entity is VehicleMake) { try { await _unitOfWork.AddAsync <VehicleMake>(entity as VehicleMake); return(await _unitOfWork.SaveChangesAsync()); } catch (Exception e) { throw e; } } else { throw new ArgumentException(); } }
/// <summary> /// Updates a single VehicleMake entity. /// </summary> /// <param name="id"></param> /// <param name="updatedItem"></param> /// <returns></returns> public void Update(Guid id, IVehicleMake updatedItem) { vehicleMakeRepository.Update(id, updatedItem); }
/// <summary> /// Updates a single VehicleMake entity. /// </summary> /// <param name="id"></param> /// <param name="updatedItem"></param> /// <returns></returns> public void Update(Guid id, IVehicleMake updatedItem) { var item = genericRepository.GetSet<VehicleMake>().SingleOrDefault(p => p.Id == id); genericRepository.Update(item, Mapper.Map<VehicleMake>(updatedItem)); }
/// <summary> /// Updates the VehicleMake async. /// </summary> /// <param name="vehicleMake"></param> /// <returns></returns> public virtual async Task<int> UpdateAsync(IVehicleMake vehicleMake) { return await Repository.UpdateAsync(vehicleMake); }
/// <summary> /// Creates new VehicleMake entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public void Create(IVehicleMake model) { genericRepository.Create(Mapper.Map<VehicleMake>(model)); }
/// <summary> /// Creates new VehicleMake entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public void Create(IVehicleMake model) { vehicleMakeRepository.Create(model); }
/// <summary> /// Updates the VehicleMake async. /// </summary> /// <param name="vehicleMake"></param> /// <returns></returns> public virtual async Task<int> UpdateAsync(IVehicleMake vehicleMake) { return await Repository.UpdateAsync<VehicleMake>(Mapper.Map<VehicleMake>(vehicleMake)); }