Пример #1
0
        public void Delete(string id)
        {
            var delivery = _iDeliveryRepository.GetById(id);

            if (delivery != null)
            {
                _iDeliveryRepository.Remove(delivery);
            }
        }
Пример #2
0
        public void RemoveDelivery(int deliveryId)
        {
            var delivery = _deliveryRepository.GetById(deliveryId);

            if (delivery == null)
            {
                throw new InvalidOperationException("Delivery doesn't exist");
            }

            _deliveryRepository.Remove(delivery);
        }
        //Methods in Domain Services are
        //   - verbs known in the ubiquitous language
        //   - have simple (primitive) attributes, no domain entities
        public bool PlanDelivery(string deliveryId, string arrivalTimeForeseen, int deliveryOrder)
        {
            try
            {
                //Start a Unit Of Work
                _unitOfWork.Start();

                //Get the delivery to be planned.
                var deliveryToBePlanned = _deliveryRepository.GetById(deliveryId);

                //Set delivery as planned
                deliveryToBePlanned.SetPlanned();
                _deliveryRepository.Update(deliveryToBePlanned);

                //Create a planned delivery with foreseen arrivaltime and delivery order
                var plannedDelivery = PlannedDelivery.Create(deliveryToBePlanned.Id, arrivalTimeForeseen, deliveryOrder);
                _plannedDeliveryRepository.Add(plannedDelivery);

                //Commit the Unit Of Work
                _unitOfWork.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                //Log your exception
                //Commit the Unit Of Work
                _unitOfWork.RollBack();
                return(false);
            }
        }
Пример #4
0
        public Delivery Edit(Guid deliveryId, string fao)
        {
            if (!CurrentUser.HasRole(UserRole.Member))
            {
                throw new DomainValidationException(Messages.InsufficientSecurityClearance, "CurrentUser");
            }
            var delivery = _deliveryRepository.GetById(deliveryId);

            if (delivery == null)
            {
                throw new ArgumentException("An invalid ID was supplied for the delivery");
            }
            delivery.Fao = fao;
            ValidateAnnotatedObjectThrowOnFailure(delivery);
            _deliveryRepository.Update(delivery);
            return(delivery);
        }
Пример #5
0
        private Delivery GetDelivery(Guid deliveryId)
        {
            var delivery = _deliveryRepository.GetById(deliveryId);

            if (delivery == null)
            {
                throw new ArgumentException("A valid delivery ID must be supplied for the item");
            }
            return(delivery);
        }
Пример #6
0
        public async Task <IActionResult> TakeDelivery(string id, [FromBody] DeliveryModel deliveryModel)
        {
            var userId     = User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault();
            var deliveryId = Guid.Parse(id);

            if (userId == null)
            {
                return(Unauthorized());
            }

            var employee = await _employeeRepository.GetEmployeeFromUserId(userId.Value);

            var delivery = await _deliveryRepository.GetById(deliveryId);

            delivery.DeliveryPerson = employee;

            deliveryModel.DeliveryPersonId = employee.Id.ToString();

            _deliveryRepository.Update(delivery);

            return(Ok(new { delivery = deliveryModel }));
        }
        public void DeleteDelivery(long deliveryId)
        {
            var delivery = _deliveryRepository.GetById(deliveryId);

            _deliveryRepository.Delete(delivery);
        }