Esempio n. 1
0
        public async Task CreateOrUpdatePlaqueToHerd(PlaqueToHerdCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdatePlaqueToHerdAsync(input);
            }
            else
            {
                await CreatePlaqueToHerdAsync(input);
            }
        }
Esempio n. 2
0
        private async Task CreatePlaqueToHerdAsync(PlaqueToHerdCreateOrUpdateInput input)
        {
            var plaqueToHerd = ObjectMapper.Map <PlaqueToHerd>(input);
            await _plaqueToHerdRepository.InsertAsync(plaqueToHerd);

            var plaqueInfo = new PlaqueInfo
            {
                Code      = Convert.ToInt64(plaqueToHerd.NationalCode),
                Latitude  = plaqueToHerd.Latitude,
                Longitude = plaqueToHerd.Longitude,
                OfficerId = plaqueToHerd.OfficerId,
                StateId   = 5
            };
            await _plaqueInfoRepository.InsertAsync(plaqueInfo);
        }
Esempio n. 3
0
        public async Task <PlaqueToHerdCreateOrUpdateInput> CheckValidation(PlaqueToHerdCreateOrUpdateInput input)
        {
            long FromCode     = 364052000000000;
            long ToCode       = 364052999999999;
            long nationalCode = Convert.ToInt64(input.NationalCode);

            if (nationalCode < FromCode)
            {
                nationalCode += FromCode;
            }
            if (nationalCode < FromCode || nationalCode > ToCode)
            {
                throw new UserFriendlyException(L("ThisCodeRangeShouldBe"));
            }

            var plaqueInfo = _plaqueInfoRepository.FirstOrDefault(x => x.Code == nationalCode);

            if (plaqueInfo != null)
            {
                throw new UserFriendlyException(L("ThisCodeIsAllocated", nationalCode));
            }

            var officer = _officerRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);

            if (officer == null)
            {
                throw new UserFriendlyException(L("TheOfficerDoesNotExists"));
            }
            else
            {
                input.OfficerId = officer.Id;
                var plaqueToOfficer = _plaqueToOfficerRepository.FirstOrDefault(x => x.FromCode <= nationalCode && x.ToCode >= nationalCode);
                if (plaqueToOfficer == null)
                {
                    throw new UserFriendlyException(L("ThisStoreIsNotAllocatedTo", nationalCode));
                }
            }



            input.NationalCode = nationalCode.ToString();
            return(input);
        }
Esempio n. 4
0
        public async Task <PlaqueToHerdGetForEditOutput> GetPlaqueToHerdForEdit(NullableIdDto <int> input)
        {
            var officer = _officerRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId);

            if (officer == null)
            {
                throw new UserFriendlyException(L("TheOfficerDoesNotExists"));
            }
            PlaqueToHerd plaqueToHerd = null;

            if (input.Id.HasValue)
            {
                plaqueToHerd = await _plaqueToHerdRepository.GetAll()
                               .Include(x => x.Officer)
                               .FirstOrDefaultAsync(x => x.Id == input.Id.Value);
            }

            var output = new PlaqueToHerdGetForEditOutput();

            //plaqueToHerd
            var newLiveStock = new PlaqueToHerdCreateOrUpdateInput();

            //newLiveStock.CreationTime = newLiveStock.CreationTime.GetShamsi();
            output.PlaqueToHerd = plaqueToHerd != null
                ? ObjectMapper.Map <PlaqueToHerdCreateOrUpdateInput>(plaqueToHerd)
                : newLiveStock;


            output.Herds = _herdRepository
                           .GetAllList()
                           .Where(x => x.CreatorUserId == AbpSession.UserId)
                           .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Code + " - " + c.HerdName + "(" + c.Name + "," + c.Family + ")"))
                           .ToList();

            return(output);
        }
Esempio n. 5
0
 private async Task UpdatePlaqueToHerdAsync(PlaqueToHerdCreateOrUpdateInput input)
 {
     var plaqueToHerd = ObjectMapper.Map <PlaqueToHerd>(input);
     await _plaqueToHerdRepository.UpdateAsync(plaqueToHerd);
 }