public bool DropOffParcel(Guid operatorId,Guid lockerBankId, Size parcelSize, string consignmentNumber, Guid agentDropOffId, Guid residentId,Guid availableLockerId)
        {
            bool isDropoffSuccess = false;

            var availableLocker = _lockerService.IsLockerAvailable(lockerBankId, availableLockerId);

            if(!availableLocker)
            {
                throw new ApplicationException("This locker is not currently available and booked by some one else.");
            }

            var parcel = _parcelRepository.GetParcelByConsignmentNumber(lockerBankId, consignmentNumber);
            //var hasConsignmentNo =context.Parcels.Any(parcel => parcel.ConsignmentNumber.ToLower() == consignmentNumber.ToLower());

            if (parcel != null)
            {
                throw new ApplicationException("This parcel already exists in the db");
            }

            var exipryTime = DateTime.Now.AddDays(3);

            var parcelId = Guid.NewGuid();

            var parcelTransaction = new ParcelTransactionDto
            {
                ParcelTransactionId = Guid.NewGuid(),
                ParcelId = parcelId,
                DropOffAgentId = agentDropOffId,
                DropoffTime = DateTime.Now,
                TransactionState = TransactionState.Dropoff,
                CreateUserId=operatorId,
                LockerId= availableLockerId,
                CreationTime=_dateTime.GetCurrentDate(),

            };

            var newParcel = new ParcelDto
            {
                ConsignmentNumber = consignmentNumber,
                IsExpired = false,
                LockerBankId = lockerBankId,
                ParcelId = parcelId,
                Size = parcelSize,
                SenderId = agentDropOffId,
                RecipientId = residentId,
                ExpiryTime = exipryTime,
                LockerId = availableLockerId,
                ParcelTransactions = new List<ParcelTransactionDto> { parcelTransaction }

            };

            _parcelRepository.AddNewParcel(newParcel);

            return isDropoffSuccess;
        }
        public void AddNewParcel(ParcelDto newParcel)
        {
            ParcelDbContext context = new ParcelDbContext(_connectionFactory.GetConnectionString());
            var agentOrganisation = context.Agents.FirstOrDefault(agent => agent.AgentId == newParcel.SenderId);

            var parcel = new ParcelEnitities.Parcel
            {
                ConsignmentNumber = newParcel.ConsignmentNumber,
                CreateUserId = newParcel.CreateUserId,
                UpdateUserId=newParcel.UpdateUserId,
                LastUpdateTime=newParcel.LastUpdateTime,
                SenderId = newParcel.SenderId,
                CreationTime = DateTime.Now,
                ExpiryTime = newParcel.ExpiryTime,
                IsExpired = newParcel.IsExpired,
                LockerBankId = newParcel.LockerBankId,
                LockerId = newParcel.LockerId,
                OrganizationId = agentOrganisation.OrganisationId,
                ParcelId = newParcel.ParcelId,
                Size = newParcel.Size,
                RecipientId = newParcel.RecipientId
            };

            foreach(var transaction in newParcel.ParcelTransactions)
            {
                if(parcel.ParcelTransactions==null)
                {
                    parcel.ParcelTransactions = new List<ParcelEnitities.ParcelTransaction>();
                }
                parcel.ParcelTransactions.Add(new ParcelEnitities.ParcelTransaction
                {
                    CreateUserId = transaction.CreateUserId,
                    CreationTime = transaction.CreationTime,
                    DropOffAgentId = transaction.DropOffAgentId,
                    DropoffTime = transaction.DropoffTime,
                    LastUpdateTime = transaction.LastUpdateTime,
                    LockerId = transaction.LockerId,
                    ParcelId = transaction.ParcelId,
                    ParcelTransactionId = transaction.ParcelTransactionId,
                    TransactionState = transaction.TransactionState,
                    UpdateUserId = transaction.UpdateUserId
                });
            }

            context.Parcels.Add(parcel);

            context.SaveChanges();
        }