public AutoBodyTypeViewModel SaveAutoBodyType(AutoBodyType autoBodyType) { var alreadyExist = AutoBodyTypeAlreadyExist(autoBodyType); if (!alreadyExist) { var result = repository.Add(autoBodyType); unitOfWork.SaveChanges(); return(autoMapper.Map <AutoBodyTypeViewModel>(result)); } else { return(null); } }
private bool AutoBodyTypeAlreadyExist(AutoBodyType autoBodyType) { //var c = unitOfWork.GetAutoSolutionContext().Database.GetDbConnection(); //var command = c.CreateCommand(); // c.Open(); // command.CommandText = "[spName] @P3, @P2, @P1"; //add parameter values //execute reader var result = (from item in unitOfWork.GetAutoSolutionContext().AutoBodyType where (item.BodyType == autoBodyType.BodyType) select item).FirstOrDefault(); return(result != null ? true : false); }
public bool UpdateAutoBodyType(AutoBodyType autoBodyType) { var checkAlreadyExist = repository.GetById(autoBodyType.Id); if (checkAlreadyExist != null) { unitOfWork.GetAutoSolutionContext().Entry(checkAlreadyExist).State = EntityState.Detached; checkAlreadyExist = autoMapper.Map <AutoBodyType>(autoBodyType); repository.Update(checkAlreadyExist); autoMapper.Map <AutoBodyTypeViewModel>(checkAlreadyExist); var resultbool = unitOfWork.SaveChanges(); return(resultbool == true ? true : false); } else { return(false); } }
public bool UpdateAutoBodyType(AutoBodyTypeViewModel autoBodyTypeViewModel) { autoBodyType = autoMapper.Map <AutoBodyType>(autoBodyTypeViewModel); return(autoBodyTypeRepository.UpdateAutoBodyType(autoBodyType)); }
public AutoBodyTypeViewModel AutoBodyTypeSave(AutoBodyTypeViewModel autoBodyTypeViewModel) { autoBodyType = autoMapper.Map <AutoBodyType>(autoBodyTypeViewModel); return(autoBodyTypeRepository.SaveAutoBodyType(autoBodyType)); }
public AutoBodyTypeService(IAutoBodyTypeRepository autoBodyTypeRepository, IMapper autoMapper, AutoBodyType autoBodyType) { this.autoBodyTypeRepository = autoBodyTypeRepository; this.autoMapper = autoMapper; this.autoBodyType = autoBodyType; }