public async Task<List<ClientChangeModelResponseDto>> GetClientCreateFilteredHistory( ClientChangeModelRequestDto model) { var request = DtoConverter.ConvertClientChangeModelRequest(model); var res = await Task.Run(() => this._priceRepository.GetClientsCreated(request)); var result = new List<ClientChangeModelResponseDto>(); foreach (var re in res) { result.Add(DtoConverter.ConvertClientChangeModelResponseDto(re)); } return result; }
public async Task<List<ClientDto>> GetClientIdFilter([FromUri]int nums) { var res = await Task.Run(() => this._priceRepository.GetClientIdFilter(nums)); var result = new List<ClientDto>(); foreach (var re in res) { result.Add(DtoConverter.ConvertClientDto(re)); } return result; }
protected override void PersistUpdatedItem(LocationPropertyData item) { string Msg = string.Format("LocationPropertyData '{0}' has been updated.", item.Value.ToString()); item.UpdatingEntity(); var converter = new DtoConverter(); var dto = converter.ToLocationPropertyDataDto(item); Repositories.ThisDb.Update(dto); LogHelper.Info(typeof(LocationPropertyDataRepository), Msg); }
public async Task<List<PriceGroupDataResponseDto>> GetPriceGroupData(PriceGroupDataRequestDto model) { var request = DtoConverter.ConvertDataRequest(model); var res = await Task.Run(() => this._priceRepository.GetPriceGroupData(request)); var result = new List<PriceGroupDataResponseDto>(); foreach (var re in res) { result.Add(DtoConverter.ConvertDataResponseDto(re)); } return result; }
public async Task<List<PriceGroupToClientDto>> GetClientsInfo(int groupId) { var res = await Task.Run(() => this._priceRepository.GetClientsInfo(groupId)); var result = new List<PriceGroupToClientDto>(); foreach (var priceList in res) { result.Add(DtoConverter.ConvertPriceGroupToClientDto(priceList)); } return result; }
private bool TryApplyTransaction() { try { Thread.Sleep(TimeSpan.FromSeconds(20)); TransactionManagerServiceProxy proxyForTM = new TransactionManagerServiceProxy(ConfigurationManager.AppSettings["TM"]); bool pom = false; while (!pom) { pom = proxyForTM.StartEnlist().GetAwaiter().GetResult(); } proxyForTM.Enlist().GetAwaiter().GetResult(); NDSModelProxy proxyForScada = new NDSModelProxy(ConfigurationManager.AppSettings["SCADAM"]); CEModelProxy proxyForCE = new CEModelProxy(ConfigurationManager.AppSettings["CEM"]); bool success = false; if (proxyForScada.ModelUpdate(affectedEntities).GetAwaiter().GetResult()) { success = true; } if (proxyForCE.ModelUpdate(affectedEntities).GetAwaiter().GetResult()) { success = true; } proxyForTM.EndEnlist(success).GetAwaiter().GetResult(); try { var subscription = new Subscription(); var publisher = new Publisher(subscription.Topic, subscription.ConnectionString); var dtos = DtoConverter.Convert(networkDataModelCopy); var json = JsonTool.Serialize(new ModelUpdateEvent(dtos)); var msg = new PubSubMessage() { Content = json, ContentType = ContentType.NMS_UPDATE, Sender = Sender.NMS }; publisher.SendMessage(msg).ConfigureAwait(false).GetAwaiter().GetResult(); } catch { } return(true); } catch (Exception) { return(false); } }
public List <ITicket> GetAll() { List <ITicket> tickets = new List <ITicket>(); List <TicketDto> dtoList = DalFactory.TicketRepo.GetAll(); List <TicketDto> mergedList = TicketFilter.FilterDuplicateTickets(dtoList); foreach (var dto in mergedList) { _ticket = DtoConverter.ConvertToTicketObject(dto); tickets.Add(_ticket); } return(tickets); }
public async Task <ActionResult> GetEmployeesByProject([FromRoute] int projectId) { var employees = await Db.Set <ProjectEmployee>() .Include(pe => pe.Project) .Include(pe => pe.Employee) .Where(pe => pe.ProjectId == projectId && pe.Role == RoleType.Employee) .Select(pe => pe.Employee).ToListAsync(); if (!employees.Any()) { return(NotFound()); } return(Ok(DtoConverter.ToEmployeeDto(employees))); }
protected override void PersistNewItem(LocationType item) { string Msg = string.Format("LocationType '{0}' has been saved.", item.Name); item.AddingEntity(); var converter = new DtoConverter(); var dto = converter.ToLocationTypeDto(item); Repositories.ThisDb.Insert(dto); //item.Key = dto.Key; LogHelper.Info(typeof(LocationTypeRepository), Msg); }
internal IEnumerable <Location> GetByCustomQuery(Sql SqlQuery) { CurrentCollection.Clear(); var dtoResult = Repositories.ThisDb.Query <LocationDto>(SqlQuery).ToList(); var converter = new DtoConverter(); CurrentCollection.AddRange(converter.ToLocationEntity(dtoResult)); FillChildren(); return(CurrentCollection); }
protected override void PersistNewItem(LocationPropertyData item) { string Msg = string.Format("LocationPropertyData '{0}' has been saved.", item.Value.ToString()); item.AddingEntity(); var converter = new DtoConverter(); var dto = converter.ToLocationPropertyDataDto(item); Repositories.ThisDb.Insert(dto); //item.Key = dto.Key; //LogHelper.Info(typeof(LocationPropertyDataRepository), Msg); }
public ActionResult CreateReport(ReportDto report) { string token = HttpContext.Request.Headers["token"]; if (token != TokenEmulator) { return(Unauthorized()); } if (report == null) { return(BadRequest()); } _reports.AddReport(DtoConverter.ConvertDtoToReport(report)); return(Ok()); }
protected override void PersistUpdatedItem(LocationType item) { string Msg = string.Format("LocationType '{0}' has been updated.", item.Name); item.UpdatingEntity(); var converter = new DtoConverter(); var dto = converter.ToLocationTypeDto(item); Repositories.ThisDb.Update(dto); PersistChildren(item); LogHelper.Info(typeof(LocationTypeRepository), Msg); }
protected override void PersistDeletedItem(LocationPropertyData item, out StatusMessage StatusMsg) { StatusMessage ReturnMsg = new StatusMessage(); ReturnMsg.ObjectName = string.Concat(item.PropertyAttributes.Name, "=", item.Value.ToString()); ReturnMsg.Message = string.Format("LocationPropertyData '{0}' has been deleted.", ReturnMsg.ObjectName); var converter = new DtoConverter(); var dto = converter.ToLocationPropertyDataDto(item); Repositories.ThisDb.Delete(dto); ReturnMsg.Success = true; StatusMsg = ReturnMsg; //LogHelper.Info(typeof(LocationPropertyDataRepository), ReturnMsg.Message); }
public string FindSlackColorHexCode(int?totalSlack) { if (!totalSlack.HasValue) { return(DtoConverter.HexConverter(255, 0, 0, 0)); } int totalSlackValue = totalSlack.GetValueOrDefault(); foreach (ActivitySeverityDto activitySeverityDto in m_ActivitySeverityDtos) { if (totalSlackValue <= activitySeverityDto.SlackLimit) { return(DtoConverter.HexConverter(activitySeverityDto.ColorFormat)); } } return(DtoConverter.HexConverter(255, 0, 0, 0)); }
protected override void PersistDeletedItem(LocationTypeProperty item, out StatusMessage StatusMsg) { StatusMessage ReturnMsg = new StatusMessage(); ReturnMsg.ObjectName = item.Name; ReturnMsg.Message = string.Format("LocationTypeProperty '{0}' has been deleted.", ReturnMsg.ObjectName); var converter = new DtoConverter(); var dto = converter.ToLocationTypePropertyDto(item); Repositories.ThisDb.Delete(dto); ReturnMsg.Success = true; StatusMsg = ReturnMsg; //LogHelper.Info(typeof(LocationTypePropertyRepository), ReturnMsg.Message); }
private void ProcessProjectPlanDto(ProjectPlanDto projectPlanDto) { if (projectPlanDto == null) { throw new ArgumentNullException(nameof(projectPlanDto)); } lock (m_Lock) { ResetProject(); // Project Start Date. ProjectStartWithoutPublishing = projectPlanDto.ProjectStart; // Resources. ResourceSettingsDto = projectPlanDto.ResourceSettings; // Compilation. GraphCompilation = DtoConverter.FromDto(projectPlanDto.GraphCompilation); CyclomaticComplexity = projectPlanDto.GraphCompilation.CyclomaticComplexity; Duration = projectPlanDto.GraphCompilation.Duration; // Activities. // Be sure to do this after the resources and project start date have been added. foreach (DependentActivityDto dependentActivityDto in projectPlanDto.DependentActivities) { m_CoreViewModel.AddManagedActivity(DtoConverter.FromDto(dependentActivityDto)); } m_CoreViewModel.UpdateActivitiesAllocatedToResources(); m_CoreViewModel.SetCompilationOutput(); m_CoreViewModel.CalculateCosts(); // Arrow Graph. ArrowGraphSettingsDto = projectPlanDto.ArrowGraphSettings; ArrowGraphDto = projectPlanDto.ArrowGraph; HasStaleOutputs = projectPlanDto.HasStaleOutputs; } PublishGraphCompilationUpdatedPayload(); PublishArrowGraphDtoUpdatedPayload(); //PublishGanttChartDtoUpdatedPayload(); }
protected override void PersistNewItem(EditableLocation item) { string Msg = string.Format("Location '{0}' has been saved.", item.Name); item.AddingEntity(); this.SyncProperties(item); var converter = new DtoConverter(); var dto = converter.ToLocationDto(item); Repositories.ThisDb.Insert(dto); //item.Key = dto.Key; LogHelper.Info(typeof(LocationRepository), Msg); PersistChildren(item); }
public IActionResult PostWithErrorHandling(int customerId, [FromBody] CustomerDto dto) { dto.Id = customerId; Log("POST with {0}", customerId); // handle validation errors at DTO level if (!this.ModelState.IsValid) { Log("Model State invalid"); return(this.BadRequest(this.ModelState)); } // handle customer creation errors var cust = DtoConverter.DtoToCustomer(dto); if (cust == null) { Log("Customer could not be created from DTO"); return(this.BadRequest("Customer could not be created from DTO")); } // hook into the domain event DomainEvents.EmailAddressChanged += NotifyCustomerWhenEmailChanged; try { _dao.Upsert(cust); return(this.Ok()); } catch (Exception ex) { // handle database errors var errMsg = $"Exception: {ex.Message}"; Log("Exception: {0}", ex.Message); return(new ContentResult { Content = errMsg, StatusCode = 500 }); } finally { // unhook from the domain event no matter what happens DomainEvents.EmailAddressChanged -= NotifyCustomerWhenEmailChanged; } }
private ProjectPlanDto BuildProjectPlanDto() { lock (m_Lock) { return(new ProjectPlanDto() { ProjectStart = ProjectStart, DependentActivities = Activities.Select(x => DtoConverter.ToDto(x)).ToList(), ResourceSettings = ResourceSettingsDto.Copy(), ArrowGraphSettings = ArrowGraphSettingsDto.Copy(), GraphCompilation = DtoConverter.ToDto(GraphCompilation, CyclomaticComplexity.GetValueOrDefault(), Duration.GetValueOrDefault()), ArrowGraph = ArrowGraphDto != null?ArrowGraphDto.Copy() : new ArrowGraphDto() { Edges = new List <ActivityEdgeDto>(), Nodes = new List <EventNodeDto>(), IsStale = false }, HasStaleOutputs = HasStaleOutputs }); } }
internal IEnumerable <Location> GetNearestLocations(double SearchLat, double SearchLong, int QuantityReturned, Guid FilterByLocationTypeKey) { CurrentCollection.Clear(); var sql = new Sql(); sql.Select(string.Format("TOP({0}) *", QuantityReturned)) .From <LocationDto>() .Append(GeographyHelper.GetGeoNearestSql(SearchLat, SearchLong, FilterByLocationTypeKey)); var dtoResult = Repositories.ThisDb.Query <LocationDto>(sql).ToList(); var converter = new DtoConverter(); CurrentCollection.AddRange(converter.ToLocationEntity(dtoResult)); FillChildren(); return(CurrentCollection); }
internal IEnumerable <Location> GetByGeoSearch(double SearchLat, double SearchLong, int MilesDistance, Guid FilterByLocationTypeKey) { CurrentCollection.Clear(); var sql = new Sql(); sql.Select("*") .From <LocationDto>() .Append(GeographyHelper.GetGeoSearchSql(SearchLat, SearchLong, MilesDistance, FilterByLocationTypeKey)); var dtoResult = Repositories.ThisDb.Query <LocationDto>(sql).ToList(); var converter = new DtoConverter(); CurrentCollection.AddRange(converter.ToLocationEntity(dtoResult)); FillChildren(); return(CurrentCollection); }
internal IEnumerable <Location> GetByType(Guid LocationTypeKey) { CurrentCollection.Clear(); var sql = new Sql(); sql.Select("*") .From <LocationDto>() .Where <LocationDto>(n => n.LocationTypeKey == LocationTypeKey); var dtoResult = Repositories.ThisDb.Fetch <LocationDto>(sql).ToList(); var converter = new DtoConverter(); CurrentCollection.AddRange(converter.ToLocationEntity(dtoResult)); FillChildren(); return(CurrentCollection); }
public IEnumerable <Location> GetByName(string LocationName) { CurrentCollection.Clear(); var sql = new Sql(); sql.Select("*") .From <LocationDto>() .Where <LocationDto>(n => n.Name == LocationName); var dtoResult = Repositories.ThisDb.Fetch <LocationDto>(sql).ToList(); var converter = new DtoConverter(); CurrentCollection.AddRange(converter.ToLocationEntity(dtoResult)); FillChildren(); return(CurrentCollection); }
private bool TryApplyTransaction() { TransactionManagerProxy proxyForTM = new TransactionManagerProxy(); //Zapocni transakciju i prijavi se na nju bool pom = false; while (!pom) { pom = proxyForTM.StartEnlist(); } proxyForTM.Enlist(); //Posalji Scadi i CEu novi model NMSSCADAProxy proxyForScada = new NMSSCADAProxy(); NMSCalculationEngineProxy proxyForCE = new NMSCalculationEngineProxy(); bool success = false; if (proxyForScada.ModelUpdate(affectedEntities)) { success = true; } if (proxyForCE.ModelUpdate(affectedEntities)) { success = true; } proxyForTM.EndEnlist(success); try { var instance = NMSServiceBus.StartInstance().GetAwaiter().GetResult(); var dtos = DtoConverter.Convert(networkDataModelCopy); var command = new ModelUpdateCommand(dtos); instance.Send(command).ConfigureAwait(false).GetAwaiter().GetResult(); } catch { } return(success); }
/// <summary> /// Creates a new Answer for this datasetId /// </summary> /// <remarks> /// Gets information for all vehicles in parallel. /// When information for a vehicle returns, get the information for its dealer, unless we have it or are already getting it. /// Wait for all vehicle and dealer information, transform it into an Answer, then return the Answer. /// </remarks> private async Task <Answer> GetAnswer(string datasetId) { ICollection <int> vehicleIds = (await apiService.GetVehicles(datasetId)).VehicleIds; Dictionary <int, ICollection <DtoVehicle> > dealerVehicleMap = new Dictionary <int, ICollection <DtoVehicle> >(); var tasks = new List <Task <Model.Dealers.Dealer> >(); foreach (int vehicleId in vehicleIds) { // Get all vehicle information in parallel var dealer = apiService.GetVehicle(datasetId, vehicleId).ContinueWith(task => { if (task.IsFaulted) { throw GetInnerMostException(task.Exception); } Vehicle vehicle = task.Result; int dealerId = vehicle.DealerId; bool dealerAlreadyExists = UpdateDealerVehicleMap(dealerVehicleMap, dealerId, vehicle); // Get this vehicle's dealer name if we aren't already getting it return(dealerAlreadyExists ? null : apiService.GetDealer(datasetId, dealerId).Result); }); tasks.Add(dealer); } // Wait for all tasks to finish then return Answer return(await Task.WhenAll(tasks). ContinueWith(task => { if (task.IsFaulted) { throw GetInnerMostException(task.Exception); } return DtoConverter.From(dealerVehicleMap, task.Result); })); }
public IActionResult GetWithErrorHandling(int customerId) { Log("GetWithErrorHandling {0}", customerId); // first create the customer id // it might be null, so handle that case var custId = CustomerId.Create(customerId); if (custId == null) { Log("CustomerId is not valid"); return(BadRequest("CustomerId is not valid")); } try { // look up the customer in the database // it might be null, so handle that case var cust = _dao.GetById(custId); if (cust == null) { Log("Customer not found"); return(NotFound()); } // this should always succeed var dto = DtoConverter.CustomerToDto(cust); // return return(Ok(dto)); } catch (Exception ex) { // handle database errors var errMsg = $"Exception: {ex.Message}"; Log("Exception: {0}", ex.Message); return(new ContentResult { Content = errMsg, StatusCode = 500 }); } }
/// <summary> /// Adds this dealer to our dealer dictionary, and adds this vehicle to the dealer's vehicle list. /// </summary> /// <returns> /// Returns true if this dealer was already in our dictionary, otherwise false. /// </returns> private bool UpdateDealerVehicleMap(Dictionary <int, ICollection <DtoVehicle> > dictionary, int dealerId, Vehicle vehicle) { bool dealerAlreadyExists; ICollection <DtoVehicle> vehicleList = new List <DtoVehicle>(); lock (dictionary) { dealerAlreadyExists = dictionary.ContainsKey(dealerId); if (dealerAlreadyExists) { vehicleList = dictionary[dealerId]; } else { dictionary.Add(dealerId, vehicleList); } } vehicleList.Add(DtoConverter.From(vehicle)); return(dealerAlreadyExists); }
protected override Location PerformGet(Guid Key) { var sql = new Sql(); sql .Select("*") .From <LocationDto>() .Where <LocationDto>(n => n.Key == Key); var dtoResult = Repositories.ThisDb.Fetch <LocationDto>(sql).FirstOrDefault(); if (dtoResult == null) { return(null); } var converter = new DtoConverter(); var entity = converter.ToLocationEntity(dtoResult); return(entity); }
protected override void PersistUpdatedItem(Location item) { string Msg = string.Format("Location '{0}' has been updated.", item.Name); item.UpdatingEntity(); var converter = new DtoConverter(); var dto = converter.ToLocationDto(item); Repositories.ThisDb.Update(dto); foreach (var prop in item.PropertyData) { prop.UpdatingEntity(); var pDto = converter.ToLocationPropertyDataDto(prop); Repositories.ThisDb.Update(pDto); } this.UpdateDbGeography(item); LogHelper.Info(typeof(LocationRepository), Msg); }