public async Task <QueueResult> Handle(string data) { QueueResult result = new QueueResult(Data.Enums.ProcessType.DeleteCountry); if (string.IsNullOrEmpty(data)) { result.ExceptionCode = ExceptionCode.MissingQueueData; } CountryQueue countryQueue = null; try { countryQueue = JsonConvert.DeserializeObject <CountryQueue>(data); CountryLogic countryLogic = new CountryLogic(this.db, result.AdditionalData, this.loggerFactory); await countryLogic.DeleteCountry(countryQueue); result.AdditionalData.Add("countryId", countryQueue.Id.ToString()); result.AdditionalData.Add("countryName", countryQueue.Name); result.Status = Status.Success; } catch (Exception ex) { HandleException(ex, result, countryQueue); } return(result); }
private async Task CheckDelete(CountryQueue countryQueue) { var relatedCity = await this.db.GetAllCitiesForCountry(countryQueue.TenantId, countryQueue.Id.Value).FirstOrDefaultAsync(); if (relatedCity != null) { throw new CountryHasRelatedCity($"Country ({countryQueue.Id}) has related city ({relatedCity.Id})", relatedCity.Id, relatedCity.Name); } }
public async Task DeleteCountry(CountryQueue countryQueue) { await CheckDelete(countryQueue); Country country = await this.db.GetCountryById(countryQueue.TenantId, countryQueue.Id.Value).FirstOrDefaultAsync(); this.db.Countries.Remove(country); await this.db.SaveChangesAsync(); this.logger.LogCustomInformation($"Country '{country.Name}' with id '{country.Id}' has successfully deleted", countryQueue.TenantId.ToString(), countryQueue.UserPerformingAction.ToString()); }
public async Task EditCountry(CountryQueue countryQueue) { await CheckAddEdit(countryQueue); Country country = await this.db.GetCountryById(countryQueue.TenantId, countryQueue.Id.Value).FirstOrDefaultAsync(); country.Name = countryQueue.Name; country.Iso3Code = countryQueue.Iso3Code; country.Iso2Code = countryQueue.Iso2Code; country.NumericCode = countryQueue.NumericCode; country.Status = countryQueue.Status; await this.db.SaveChangesAsync(); this.logger.LogCustomInformation($"Country '{country.Name}' with id '{country.Id}' has successfully updated", countryQueue.TenantId.ToString(), countryQueue.UserPerformingAction.ToString()); }
public async Task EditCountry(CountryVM country) { CountryQueue countryQueue = Mapper.Map <CountryVM, CountryQueue>(country, options => { options.AfterMap((src, dest) => dest.UserPerformingAction = this.UserId); options.AfterMap((src, dest) => dest.TenantId = this.TenantId); }); ProcessQueueHistory processQueueHistory = new ProcessQueueHistory() { Data = JsonConvert.SerializeObject(countryQueue), AddedById = this.UserId, TenantId = this.TenantId, Status = Data.Enums.ResultStatus.Waiting, Type = Data.Enums.ProcessType.EditCountry }; await this.queueHandler.AddToQueue(processQueueHistory); }
public async Task <Guid> AddCountry(CountryQueue countryQueue) { await CheckAddEdit(countryQueue); Country country = new Country() { Name = countryQueue.Name, Iso2Code = countryQueue.Iso2Code, Iso3Code = countryQueue.Iso3Code, NumericCode = countryQueue.NumericCode, Status = countryQueue.Status, TenantId = countryQueue.TenantId }; this.db.Countries.Add(country); await this.db.SaveChangesAsync(); this.logger.LogCustomInformation($"County '{country.Name}' with id '{country.Id}' has successfully created", countryQueue.TenantId.ToString(), countryQueue.UserPerformingAction.ToString()); return(country.Id); }
public async Task DeleteCountry(Guid id) { CountryQueue countryQueue = new CountryQueue() { Id = id, TenantId = this.TenantId, UserPerformingAction = this.UserId }; ProcessQueueHistory processQueueHistory = new ProcessQueueHistory() { Data = JsonConvert.SerializeObject(countryQueue), AddedById = this.UserId, TenantId = this.TenantId, Status = Data.Enums.ResultStatus.Waiting, Type = Data.Enums.ProcessType.DeleteCountry }; await this.queueHandler.AddToQueue(processQueueHistory); }
private async Task CheckAddEdit(CountryQueue countryQueue) { await CheckForSameName(countryQueue.Name.Trim(), countryQueue.Id, countryQueue.TenantId); }