public async Task <IndexDto> UpdateAsync(UpdateIndexDto input) { CheckBeforeUpdate(input); var nationality = await _repository.GetAsync(input.Id); ObjectMapper.Map <UpdateIndexDto, Nationality>(input, nationality); var updatedNationality = await _repository.UpdateAsync(nationality); return(ObjectMapper.Map <IndexDto>(updatedNationality)); }
public static void Send(Farm farm, EUpdateMethod updateMethod) { var dto = new UpdateIndexDto { FarmId = farm.FarmId, // UpdateTime = farm.UpdateDateTime, UpdateMethod = updateMethod }; QueueClient.Send(new BrokeredMessage(dto)); }
public async Task <IndexDto> UpdateAsync(UpdateIndexDto input) { CheckBeforeUpdate(input); var status = await _repository.GetAsync(input.Id); ObjectMapper.Map <UpdateIndexDto, CaseStatus>(input, status); var updatedCaseStatus = await _repository.UpdateAsync(status); return(ObjectMapper.Map <IndexDto>(updatedCaseStatus)); }
public async Task <IndexDto> UpdateAsync(UpdateIndexDto input) { CheckBeforeUpdate(input); var country = await _repository.GetAsync(input.Id); ObjectMapper.Map <UpdateIndexDto, Country>(input, country); var updatedCountry = await _repository.UpdateAsync(country); return(ObjectMapper.Map <IndexDto>(updatedCountry)); }
private void CheckBeforeUpdate(UpdateIndexDto input) { var validationResultMessage = string.Empty; if (_repository.FirstOrDefault(x => x.Name == input.Name && x.Id != input.Id) != null) { validationResultMessage = L(ValidationResultMessage.NameAleadyExist); } if (!string.IsNullOrEmpty(validationResultMessage)) { throw new UserFriendlyException(validationResultMessage); } }
private async Task HandleMessage(UpdateIndexDto dto) { using (var db = new ApplicationDbContext()) { Farm farm; switch (dto.UpdateMethod) { case EUpdateMethod.Create: farm = await db.Farms.Include(f => f.Products).Where(f => f.FarmId == dto.FarmId).FirstAsync(); //good idea but different time zone or system time on different servers do not allow to use a timestamp to filter out old messages if (farm != null && farm.UpdateDateTime > farm.IndexDateTime) // && farm.UpdateDateTime == dto.UpdateTime) { AddFarmToIndex(farm, _indexWriter, db); await db.SaveChangesAsync(); _indexWriter.Commit(); } break; case EUpdateMethod.Update: farm = await db.Farms.Include(f => f.Products).Where(f => f.FarmId == dto.FarmId).FirstAsync(); if (farm != null && farm.UpdateDateTime > farm.IndexDateTime) // && farm.UpdateDateTime == dto.UpdateTime) { UpdateFarmInIndex(farm, _indexWriter, db); await db.SaveChangesAsync(); _indexWriter.Commit(); } break; case EUpdateMethod.Delete: farm = await db.Farms.FindAsync(dto.FarmId); if (farm != null) { DeleteFarmFromIndex(farm, _indexWriter, db); await db.SaveChangesAsync(); _indexWriter.Commit(); } break; } } }