private async Task CreatePlaqueChangeAsync(PlaqueChangeCreateOrUpdateInput input) { if (input.PlaqueId.HasValue) { var plaqueInfo = _plaqueInfoRepository.Get(input.PlaqueId.Value); plaqueInfo.StateId = input.NewStateId; await _plaqueInfoRepository.UpdateAsync(plaqueInfo); } else { var plaqueInfo = new PlaqueInfo { Code = Convert.ToInt64(input.PlaqueCode), OfficerId = input.OfficerId, StateId = input.NewStateId, Latitude = "", Longitude = "" }; await _plaqueInfoRepository.InsertAsync(plaqueInfo); await CurrentUnitOfWork.SaveChangesAsync(); input.PlaqueId = plaqueInfo.Id; } var plaqueChange = ObjectMapper.Map <PlaqueChange>(input); await _plaqueChangeRepository.InsertAsync(plaqueChange); }
public async Task <PlaqueChangeCreateOrUpdateInput> CheckValidation(PlaqueChangeCreateOrUpdateInput input) { var officer = _officerRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId); if (officer == null) { throw new UserFriendlyException(L("TheOfficerDoesNotExists")); } else { input.OfficerId = officer.Id; } long code = 364052000000000 + Convert.ToInt64(input.PlaqueCode); var plaqueStores = _plaqueStoreRepository .FirstOrDefault(x => x.FromCode <= code && x.ToCode >= code); if (plaqueStores == null) { throw new UserFriendlyException(L("ThePlaqueStoreDoesNotExists")); } var plaqueChanged = _plaqueChangeRepository.GetAll() .Include(x => x.Plaque) .FirstOrDefault(x => x.Plaque.Code == code); if (plaqueChanged != null) { throw new UserFriendlyException(L("ThisCodeChanged")); } var plaqueInfo = _plaqueInfoRepository.GetAll() .Include(x => x.State) .Include(x => x.Livestock) .ThenInclude(x => x.Herd) .FirstOrDefault(x => x.Code == code); if (plaqueInfo != null) { input.PlaqueId = plaqueInfo.Id; input.PreStateName = plaqueInfo.State.Name; input.PreStateId = plaqueInfo.State.Id; input.PlaqueHerdName = plaqueInfo.Livestock.Herd.HerdName; } else { input.PreStateName = "در انبار"; } input.PlaqueCode = code.ToString(); return(input); }
public async Task CreateOrUpdatePlaqueChange(PlaqueChangeCreateOrUpdateInput input) { await CheckValidation(input); if (input.Id.HasValue) { await UpdatePlaqueChangeAsync(input); } else { await CreatePlaqueChangeAsync(input); } }
private async Task UpdatePlaqueChangeAsync(PlaqueChangeCreateOrUpdateInput input) { var plaqueChange = ObjectMapper.Map <PlaqueChange>(input); await _plaqueChangeRepository.UpdateAsync(plaqueChange); }