Пример #1
0
        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)));
        }
Пример #2
0
        public async Task UpdateMake(IVehicleMake vehicle)
        {
            VehicleMake update = mapper.Map <VehicleMake>(vehicle);

            context.VehicleMakes.Update(update);
            await context.SaveChangesAsync();
        }
Пример #3
0
        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));
        }
Пример #4
0
        public async Task InsertMake(IVehicleMake vehicle)
        {
            VehicleMake create = mapper.Map <VehicleMake>(vehicle);

            context.VehicleMakes.Add(create);
            await context.SaveChangesAsync();
        }
Пример #5
0
        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);
        }
Пример #7
0
        public async Task <IVehicleMake> AddMakeAsync(IVehicleMake make)
        {
            var createdMaker = await unitOfWork.Makers.AddAsync(make);

            await unitOfWork.CommitAsync();

            return(createdMaker);
        }
Пример #8
0
        public async Task <IVehicleMake> FindById(object id)
        {
            VehicleMakeEntity vehicleEntity = await dbSet.FindAsync(id);

            IVehicleMake vehicleMake = _mapper.Map <VehicleMake>(vehicleEntity);

            return(vehicleMake);
        }
Пример #9
0
        public async Task <IVehicleMake> AddVehicleMakerAsync(IVehicleMake newMaker)
        {
            await UnitOfWork.VehicleMakeRepository.Add(Mapper.Map <Vehicle.DAL.Entities.VehicleMakeEntity>(newMaker));

            await UnitOfWork.CommitAsync();

            return(newMaker);
        }
Пример #10
0
        public async Task <ActionResult> Edit(int id)
        {
            IVehicleMake VehicleMake = await Service.GetAsync(id);

            if (VehicleMake == null)
            {
                return(HttpNotFound());
            }
            return(View(VehicleMake));
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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));
        }
Пример #15
0
 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;
            }
        }
Пример #17
0
        /// <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);
            }
        }
Пример #18
0
        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));
        }
Пример #19
0
        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);
            }
        }
Пример #21
0
        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);
        }
Пример #22
0
 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();
     }
 }
Пример #23
0
        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)));
        }
Пример #24
0
 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));
 }
Пример #25
0
        public async Task <bool> CreateVehicleMake(IVehicleMake vehicleMake)
        {
            try
            {
                await _vehicleMakeRepository.Create(vehicleMake);

                await _unitOfWork.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #26
0
        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);
            }
        }
Пример #28
0
        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);
            }
        }
Пример #29
0
        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)));
        }
Пример #30
0
        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();
            }
        }
Пример #31
0
 /// <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));
        }
Пример #33
0
 /// <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));
 }
Пример #35
0
 /// <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));
 }