Example #1
0
 public Consignment GetById(Guid id)
 {
     if (!CurrentUser.HasRole(UserRole.Member))
     {
         throw new DomainValidationException(Messages.InsufficientSecurityClearance);
     }
     return(_consignmentRepository.GetById(id));
 }
Example #2
0
        public Guid CreateOrderFromConsignment(Guid consignmentId)
        {
            var orderId     = Guid.NewGuid();
            var consignment = _consignmentRepository.GetById(consignmentId);
            var items       = _consignmentRepository.GetConsignmentItems(consignmentId);

            Create(orderId, consignment.Supplier.Id, String.Empty, GetDefaultCurrencyId());
            foreach (var item in items)
            {
                var instrument  = item.JobItem.Instrument;
                var description = String.Format("{0}, {1}, {2}", instrument.Manufacturer, instrument.ModelNo, instrument.Description);
                _orderItemService.CreateFromConsignment(
                    Guid.NewGuid(), orderId, description, 1, String.Empty, item.Instructions ?? String.Empty, 30, item.JobItem.Id, 0);
            }
            consignment.IsOrdered = true;
            _consignmentRepository.Update(consignment);
            return(orderId);
        }
Example #3
0
        public ConsignmentItem Create(Guid id, Guid jobItemId, Guid consignmentId, string instructions)
        {
            if (!CurrentUser.HasRole(UserRole.Member))
            {
                throw new DomainValidationException(Messages.InsufficientSecurityClearance);
            }
            if (id == Guid.Empty)
            {
                throw new ArgumentException("An ID must be supplied for the consignment item.");
            }
            var jobItem = _jobItemRepository.GetById(jobItemId);

            if (jobItem == null)
            {
                throw new ArgumentException("A valid ID must be supplied for the job item.");
            }
            if (jobItem.Job.IsPending)
            {
                throw new DomainValidationException(Messages.PendingJob);
            }
            var consignment = _consignmentRepository.GetById(consignmentId);

            if (consignment == null)
            {
                throw new ArgumentException("A valid ID must be supplied for the parent consignment.");
            }
            var consignmentItem = new ConsignmentItem
            {
                Id           = id,
                Consignment  = consignment,
                ItemNo       = _consignmentRepository.GetConsignmentItemCount(consignmentId) + 1,
                JobItem      = jobItem,
                Instructions = instructions
            };

            jobItem.Status = _listItemRepository.GetByType(ListItemType.StatusConsigned);
            ValidateAnnotatedObjectThrowOnFailure(consignmentItem);
            _jobItemRepository.EmitItemHistory(CurrentUser, jobItemId, 0, 0, String.Format("Item consigned on {0}", consignment.ConsignmentNo), ListItemType.StatusConsigned, ListItemType.WorkTypeAdministration);
            _consignmentItemRepository.Create(consignmentItem);
            _jobItemRepository.Update(jobItem);
            return(consignmentItem);
        }