public async Task <QueueResult> Handle(string data) { QueueResult result = new QueueResult(Data.Enums.ProcessType.EditCity); if (string.IsNullOrEmpty(data)) { result.ExceptionCode = ExceptionCode.MissingQueueData; } CityQueue cityQueue = null; try { cityQueue = JsonConvert.DeserializeObject <CityQueue>(data); CityLogic cityLogic = new CityLogic(this.db, result.AdditionalData, this.loggerFactory); await cityLogic.EditCity(cityQueue); result.AdditionalData.Add("cityId", cityQueue.Id.ToString()); result.AdditionalData.Add("cityName", cityQueue.Name); result.Status = Status.Success; } catch (Exception ex) { HandleException(ex, result, cityQueue); } return(result); }
private async Task CheckDelete(CityQueue cityQueue) { var relatedOffice = await this.db.GetAllOfficesForCity(cityQueue.TenantId, cityQueue.Id.Value).FirstOrDefaultAsync(); if (relatedOffice != null) { throw new CityHasRelatedOffice($"City ({cityQueue.Id}) has related office ({relatedOffice.Id})", relatedOffice.Id, relatedOffice.Name); } }
public async Task DeleteCity(CityQueue cityQueue) { await CheckDelete(cityQueue); City city = await this.db.GetCityById(cityQueue.TenantId, cityQueue.Id.Value).FirstOrDefaultAsync(); this.db.Cities.Remove(city); await this.db.SaveChangesAsync(); this.logger.LogCustomInformation($"City '{city.Name}' with id '{city.Id}' has successfully deleted", cityQueue.TenantId.ToString(), cityQueue.UserPerformingAction.ToString()); }
public async Task EditCity(CityQueue cityQueue) { await CheckAddEdit(cityQueue); City city = await this.db.GetCityById(cityQueue.TenantId, cityQueue.Id.Value).FirstOrDefaultAsync(); city.Name = cityQueue.Name; city.PostalCode = cityQueue.PostalCode; city.CountryId = cityQueue.CountryId; city.Status = cityQueue.Status; await this.db.SaveChangesAsync(); this.logger.LogCustomInformation($"City '{city.Name}' with id '{city.Id}' has successfully updated", cityQueue.TenantId.ToString(), cityQueue.UserPerformingAction.ToString()); }
public async Task EditCity(CityVM city) { CityQueue cityQueue = Mapper.Map <CityVM, CityQueue>(city, options => { options.AfterMap((src, dest) => dest.UserPerformingAction = this.UserId); options.AfterMap((src, dest) => dest.TenantId = this.TenantId); }); ProcessQueueHistory processQueueHistory = new ProcessQueueHistory() { Data = JsonConvert.SerializeObject(cityQueue), AddedById = this.UserId, TenantId = this.TenantId, Status = Data.Enums.ResultStatus.Waiting, Type = Data.Enums.ProcessType.EditCity }; await this.queueHandler.AddToQueue(processQueueHistory); }
public async Task <Guid> AddCity(CityQueue cityQueue) { await CheckAddEdit(cityQueue); City city = new City() { Name = cityQueue.Name, PostalCode = cityQueue.PostalCode, CountryId = cityQueue.CountryId, Status = cityQueue.Status, TenantId = cityQueue.TenantId }; this.db.Cities.Add(city); await this.db.SaveChangesAsync(); this.logger.LogCustomInformation($"City '{city.Name}' with id '{city.Id}' has successfully created", cityQueue.TenantId.ToString(), cityQueue.UserPerformingAction.ToString()); return(city.Id); }
public async Task DeleteCity(Guid id) { CityQueue cityQueue = new CityQueue() { Id = id, TenantId = this.TenantId, UserPerformingAction = this.UserId }; ProcessQueueHistory processQueueHistory = new ProcessQueueHistory() { Data = JsonConvert.SerializeObject(cityQueue), AddedById = this.UserId, TenantId = this.TenantId, Status = Data.Enums.ResultStatus.Waiting, Type = Data.Enums.ProcessType.DeleteCity }; await this.queueHandler.AddToQueue(processQueueHistory); }
private async Task CheckAddEdit(CityQueue cityQueue) { await CheckForSameName(cityQueue.Name.Trim(), cityQueue.Id, cityQueue.TenantId); }
/// <summary> /// A method that runs the solver to get the result /// </summary> public void GetShortestPath() { // Initialize for new calculations VisitedCities.Clear(); Vertex tempVertex; // Start the timer Clock.Start(); // Set the initial city into the queue Vertex currentCity = new Vertex { Point = Origin, Parent = null }; VisitedCities.Add(currentCity); CityQueue.Enqueue(currentCity); // Iterate as long as the queue has content while (CityQueue.Count != 0) { // Get the next city in the queue currentCity = CityQueue.Dequeue(); // If the goal is found, then end the search if (currentCity.Point == Goal) { break; } // Iterate for each route a city can take to another foreach (City route in currentCity.Point.Routes) { // If the city is a duplicate, skip this iteration if (VisitedCities.Select(v => v.Point).Contains(route)) { continue; } // If its a new city add it to the queue tempVertex = new Vertex { Point = route, Parent = currentCity.Point }; CityQueue.Enqueue(tempVertex); VisitedCities.Add(tempVertex); } } // Trace back the shortest path List <City> cities = new List <City>(); while (currentCity.Parent != null) { cities.Add(currentCity.Point); currentCity = VisitedCities.FirstOrDefault(c => c.Point == currentCity.Parent); } var shortestPath = new Trip(Origin, cities.OrderBy(c => c.Index).ToList(), false); // Stop the timer and display the result on screen Clock.Stop(); MessageBox.Show($"Time: {Clock.Elapsed}\n" + $"Path: {shortestPath}"); }