public OperationDetails Add(EngineDTO engine) { var entity = enginesRepository.GetFirst(e => e.Name == engine.Name); if (entity == null) { entity = new Engine() { Name = engine.Name, //TODO: DescElementSelector = engine.DescElementSelector, QueryUrl = engine.QueryUrl, ResultElementSelector = engine.ResultElementSelector, TitleElementSelector = engine.TitleElementSelector, LinkElementSelector = engine.LinkElementSelector }; try { enginesRepository.AddNew(entity); unitOfWork.Commit(); return(new OperationDetails(true, $"Поисковый движок успешно добавлен!", "EnginesService.Add")); } catch (DbUpdateException ex) { return(new OperationDetails(false, ex.Message, "EnginesService.Add", ex.InnerException.Message)); } } else { return(new OperationDetails(false, $"Поисковый движок с названием \"{engine.Name}\" уже существует!", "EnginesService.Add")); } }
public OperationDetails Update(EngineDTO engine) { var entity = enginesRepository.GetFirst(e => e.Id == engine.Id); if (entity == null) { return(new OperationDetails(false, $"Ошибка, поисковый движок с Id={engine.Id} не найден!", "EnginesService.Update")); } else { entity.Name = engine.Name; //TODO: entity.DescElementSelector = engine.DescElementSelector; entity.QueryUrl = engine.QueryUrl; entity.ResultElementSelector = engine.ResultElementSelector; entity.TitleElementSelector = engine.TitleElementSelector; try { unitOfWork.Commit(); return(new OperationDetails(true, $"Поисковый движок успешно обновлен!", "EnginesService.Update")); } catch (DbUpdateException ex) { return(new OperationDetails(false, ex.Message, "EnginesService.Update", ex.InnerException)); } } }
public IActionResult NewEngine(EngineVM engine) { if (ModelState.IsValid) { EngineDTO engineDTO = new EngineDTO { Name = engine.Name, LinkElementSelector = engine.LinkElementSelector, DescElementSelector = engine.DescElementSelector, QueryUrl = engine.QueryUrl, ResultElementSelector = engine.ResultElementSelector, TitleElementSelector = engine.TitleElementSelector }; var result = enginesService.Add(engineDTO); logger.LogInformation(result.Message); if (result.Succeedeed) { return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, result.Message); } } return(View()); }
public void InsertEngine(EngineDTO engineDTO) { Engine engine = this.mapper.Map <Engine>(engineDTO); engine.Cars = this.GetCarsByBrand(engineDTO.Brands); this.unitOfWork.Engines.Add(engine); this.unitOfWork.Complete(); }
private EngineVM GetEngineVM(EngineDTO engine) => new EngineVM { DescElementSelector = engine.DescElementSelector, LinkElementSelector = engine.LinkElementSelector, Name = engine.Name, QueryUrl = engine.QueryUrl, ResultElementSelector = engine.ResultElementSelector, TitleElementSelector = engine.TitleElementSelector, Id = engine.Id };
public void ShouldMapEngineDTOToEngine() { //Arrange var engine = new Engine(); var engineDTO = new EngineDTO(); var engineType = engine.GetType(); //Act var result = Mapper.Map <Engine>(engineDTO); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, engineType); }
public Engine ConvertEngine(EngineDTO engineDTO) { return(new Engine { Id = engineDTO.Id, Cylinders = engineDTO.Cylinders, HP = engineDTO.HP, Liters = engineDTO.Liters, Name = engineDTO.Name, Price = engineDTO.Price, Producer = engineDTO.Producer, Torque = engineDTO.Torque, Type = engineDTO.Type }); }
public Engine MapToEngineEntity(EngineDTO engineDTO) { var engine = new Engine(); engine.ID = engineDTO.ID; engine.NoOfCylinders = engineDTO.NoOfCylinders; engine.EngineSizeCC = engineDTO.EngineSizeCC; engine.PowerKW = engineDTO.PowerKW; engine.CylinderConfig = (CylinderConfiguration)engineDTO.CylinderConfigDTO; engine.DriveType = (DriveType)engineDTO.DriveTypeDTO; engine.FuelType = (FuelType)engineDTO.FuelTypeDTO; engine.FuelEconomy = engineDTO.FuelEconomy; engine.PowerToWeight = engineDTO.PowerToWeight; return(engine); }
public EngineDTO MapToEngineDTO(Engine engine) { var engineDTO = new EngineDTO(); engineDTO.ID = engine.ID; engineDTO.NoOfCylinders = engine.NoOfCylinders; engineDTO.EngineSizeCC = engine.EngineSizeCC; engineDTO.PowerKW = engine.PowerKW; engineDTO.CylinderConfigDTO = (CylinderConfigurationDTO)engine.CylinderConfig; engineDTO.DriveTypeDTO = (DriveTypeDTO)engine.DriveType; engineDTO.FuelTypeDTO = (FuelTypeDTO)engine.FuelType; engineDTO.FuelEconomy = engine.FuelEconomy; engineDTO.PowerToWeight = engine.PowerToWeight; return(engineDTO); }
public static string SearchBing(string value) { EngineDTO engine = new EngineDTO() { Id = "Bing", Url = "https://api.cognitive.microsoft.com/bing/v7.0/search?q={0}", Key = "3fa160597390418ab23c7ca9a5c8d311" }; string result = ""; string requestUrl = String.Format(engine.Url, value); HttpProvider http = new HttpProvider(requestUrl, engine.Key); result = http.GetResponse(); return(result); }
public void UpdateEngine(EngineDTO engineDTO) { Engine engine = unitOfWork.Engines.GetByCylindersNumber(engineDTO.CylindersNumber); if (engine != null) { engine.Description = engineDTO.Description; engine.Cars = this.GetCarsByBrand(engineDTO.Brands); this.unitOfWork.Engines.Update(engine); this.unitOfWork.Complete(); } else { this.InsertEngine(engineDTO); } }
public static string SearchGoogle(string value) { EngineDTO engine = new EngineDTO() { Id = "Google", Url = "https://www.googleapis.com/customsearch/v1?q={0}&cx={1}&key={2}", Key = "AIzaSyA2Isp3M6aO4MNStWfW3x3F-1xsOtsTdf4", SpecificEngineId = "008769807058408683812:zm9ptt-wlcs" }; string result = ""; string requestUrl = String.Format(engine.Url, value, engine.SpecificEngineId, engine.Key); HttpProvider http = new HttpProvider(requestUrl); result = http.GetResponse(); return(result); }
public EngineDTO ConvertToEngineDTO(Engine engine) { EngineDTO engineDTO = new EngineDTO() { Id = engine.Id, Cylinders = engine.Cylinders, HP = engine.HP, Liters = engine.Liters, Name = engine.Name, Price = engine.Price, Producer = engine.Producer, Torque = engine.Torque, Type = engine.Type }; return(engineDTO); }
public override bool Equals(object obj) { if (ReferenceEquals(obj, null)) { return(false); } if (!(obj is EngineDTO)) { return(false); } EngineDTO engine = obj as EngineDTO; return(Id == engine.Id && Name == engine.Name && QueryUrl == engine.QueryUrl && ResultElementSelector == engine.ResultElementSelector && TitleElementSelector == engine.TitleElementSelector && DescElementSelector == engine.DescElementSelector && LinkElementSelector == engine.LinkElementSelector); }
private Task <SearchResult> RunSearchTask(Engine eng, string words) { var engine = new EngineDTO { DescElementSelector = eng.DescElementSelector, LinkElementSelector = eng.LinkElementSelector, Name = eng.Name, QueryUrl = eng.QueryUrl, ResultElementSelector = eng.ResultElementSelector, TitleElementSelector = eng.TitleElementSelector }; var request = new RequestDTO { EngineId = eng.Id, Words = words, Engine = engine }; return(Task.Run(() => new Parser().Execute(request))); }
public void Put([FromBody] EngineDTO engineDTO) { this.engineService.UpdateEngine(engineDTO); }
public void Post([FromBody] EngineDTO engineDTO) { this.engineService.InsertEngine(engineDTO); }
public void AddToEngines(EngineDTO engineDTO) { base.AddObject("Engines", engineDTO); }
public async Task <IActionResult> GetVehiclesByEngine(EngineDTO engineDTO) { throw new NotImplementedException(); }
public static EngineDTO CreateEngineDTO(global::System.Guid ID, global::System.DateTime createDate, decimal maxThrust, global::System.Guid engineTypeId, global::System.Guid airlinesId, global::System.Guid importCategoryId, global::System.Collections.ObjectModel.ObservableCollection<EngineOwnershipHistoryDTO> engineOwnerShipHistories, global::System.Collections.ObjectModel.ObservableCollection<EngineBusinessHistoryDTO> engineBusinessHistories) { EngineDTO engineDTO = new EngineDTO(); engineDTO.Id = ID; engineDTO.CreateDate = createDate; engineDTO.MaxThrust = maxThrust; engineDTO.EngineTypeId = engineTypeId; engineDTO.AirlinesId = airlinesId; engineDTO.ImportCategoryId = importCategoryId; if ((engineOwnerShipHistories == null)) { throw new global::System.ArgumentNullException("engineOwnerShipHistories"); } engineDTO.EngineOwnerShipHistories = engineOwnerShipHistories; if ((engineBusinessHistories == null)) { throw new global::System.ArgumentNullException("engineBusinessHistories"); } engineDTO.EngineBusinessHistories = engineBusinessHistories; return engineDTO; }