Example #1
0
        public async Task CreateOrUpdateHerd(HerdCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdateHerdAsync(input);
            }
            else
            {
                await CreateHerdAsync(input);
            }
        }
Example #2
0
        public async Task <HerdCreateOrUpdateInput> CheckValidation(HerdCreateOrUpdateInput input)
        {
            var officer = _officerRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);

            if (officer == null)
            {
                throw new UserFriendlyException(L("TheOfficerDoesNotExists"));
            }
            else
            {
                input.OfficerId = officer.Id;
            }

            return(input);
        }
Example #3
0
        private async Task CreateHerdAsync(HerdCreateOrUpdateInput input)
        {
            var herd = ObjectMapper.Map <Herd>(input);
            await _herdRepository.InsertAsync(herd);

            await CurrentUnitOfWork.SaveChangesAsync();

            var herdGeoLog = new HerdGeoLog
            {
                HerdId       = herd.Id,
                Latitude     = herd.Latitude,
                Longitude    = herd.Longitude,
                CreationTime = herd.CreationTime
            };
            await _herdGeoLogInfoRepository.InsertAsync(herdGeoLog);

            if (herd.Id > 0)
            {
                var officer = _officerRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);
                var message = "گله شما با کد " + herd.Code + " در سامانه دامیار توسط " + officer?.Name + " " + officer?.Family + " ثبت شد.";
                await _sms98Sender.SendAsync(herd.Mobile.Replace("-", ""), message);
            }
        }
Example #4
0
 private async Task UpdateHerdAsync(HerdCreateOrUpdateInput input)
 {
     var herd = ObjectMapper.Map <Herd>(input);
     await _herdRepository.UpdateAsync(herd);
 }