Beispiel #1
0
 private void updateComputedValues(ref WorkOrder record)
 {
     record.statusES          = lRepo.GetById(record.statusID).text_ES;
     record.statusEN          = lRepo.GetById(record.statusID).text_EN;
     record.transportMethodEN = tpServ.Get(record.transportProviderID).text_EN;
     record.transportMethodES = tpServ.Get(record.transportProviderID).text_ES;
 }
        public IHttpActionResult Get(int id)
        {
            var result = map.Map <Domain.TransportProvider, ViewModel.TransportProvider>(serv.Get(id));

            if (result == null)
            {
                return(NotFound());
            }

            return(Json(new { data = result }));
        }
        public bool validateTransportRules(WorkOrder order)
        {
            if (order.workAssignments == null)
            {
                throw new MacheteValidationException("WorkAssignments can't be null");
            }

            if (order.workAssignments.Count() == 0)
            {
                throw new MacheteValidationException("WorkAssignments can't be empty");
            }

            if (order.transportProviderID == 0)
            {
                throw new MacheteValidationException("Transport provider can't be 0");
            }

            var transMethod = tpServ.Get(order.transportProviderID);

            if (transMethod == null)
            {
                throw new MacheteValidationException("Transport method lookup returned null");
            }

            var trRules = trServ.GetMany(a => a.lookupKey == transMethod.key);

            if (trRules == null || trRules.Count() == 0)
            {
                throw new MacheteValidationException("TransportMethod does not have rules associated with it");
            }

            var trRule = trRules.Where(r => r.zipcodes.Contains(order.zipcode) || r.zipcodes.Contains("*")).First();

            if (trRule == null)
            {
                throw new MacheteValidationException("No rule matching order zipcode");
            }
            //
            // the code assumes that IDs sent from the client
            // are unique and sequential. They determine price and are prescribed for the pricing logic:
            var i = 1;

            foreach (var wa in order.workAssignments.OrderBy(a => a.ID))
            {
                if (wa.ID != i)
                {
                    throw new MacheteValidationException("Work Assignment ID invalid");
                }
                i++;
            }

            foreach (var wa in order.workAssignments)
            {
                //
                // This assumes that the IDs are going to come in as 1,2,3,4...they're reset
                // later on down in the code
                var costRule = trRule.costRules.First(c => wa.ID >= c.minWorker && wa.ID <= c.maxWorker);
                if (costRule == null)
                {
                    throw new MacheteValidationException("No cost rule matching workAssignment ID");
                }

                if (wa.transportCost != costRule.cost)
                {
                    throw new MacheteValidationException("Unexpected transport cost from client");
                }
            }

            return(true);
        }