Example #1
0
        public bool Save(MilkRunViewModel model, User user)
        {
            const int humanMilkProductId = 5;

            model.CreatedByUserId = user.UserID;
            var runLog        = _mapper.Map(model);
            var prods         = Enumerable.Repeat(humanMilkProductId, model.BoxQty).ToList();
            var dal           = new RunLogDAL();
            var vehicleTypeId = dal.GetVehicleId(model.VehicleType);

            if (!vehicleTypeId.HasValue)
            {
                throw new InvalidOperationException($"Unknown VehicleType [{model.VehicleType}] while trying to save milk run");
            }
            runLog.VehicleTypeID = vehicleTypeId.Value;
            if (model.RunLogId == 0)
            {
                return(dal.CreateRunLog(runLog, prods) > 0);
            }

            var to = dal.Get(model.RunLogId);

            UpdatePropertyValues(runLog, to);
            return(dal.Update(to));
        }
Example #2
0
        public bool LogMilkRun(MilkRunViewModel model)
        {
            Authenticate();
            var logMessage = $"RunLogId [{model.RunLogId}], controllerMemberId [{model.ControllerMemberId}], riderMemberId [{model.RiderMemberId}], runDate [{model.RunDate}], collectTime [{model.CollectTime}], deliverTime [{model.DeliverTime}], homeSafeTime  [{model.HomeSafeTime}], vehicleType  [{model.VehicleType}], collectPostcode [{model.CollectPostcode}], collectionLocationId [{model.CollectionLocationId}], deliverToPostcode [{model.DeliverToPostcode}] deliverToLocationId [{model.DeliverToLocationId}], quantity [{model.BoxQty}] notes [{model.Notes}]";

            _logger.Debug(logMessage);
            var result = new MilkLogBLL(new MilkRunMapper()).Save(model, CurrentUser());

            return(result);
        }
Example #3
0
 public void Setup()
 {
     _fixture        = new Fixture();
     _classUnderTest = new MilkRunMapper();
     _input          = _fixture.Build <MilkRunViewModel>()
                       .With(x => x.RunDate, "07 Nov 2019")
                       .With(x => x.CollectTime, "23:11")
                       .With(x => x.DeliverTime, "01:35")
                       .With(x => x.HomeSafeTime, "13:25")
                       .Create();
 }
Example #4
0
        public RunLog Map(MilkRunViewModel model)
        {
            const int privateAddressLocationId = 19;

            if (!DateTime.TryParse(model.RunDate, out var dutyDate))
            {
                throw new ArgumentException($"RunDate {model.RunDate} is not a valid date");
            }

            var collectDateTime      = ToDateTime(model.CollectTime, dutyDate);
            var deliverDateTime      = ToDateTime(model.DeliverTime, dutyDate);
            var homeSafe             = ToDateTime(model.HomeSafeTime, dutyDate);
            var collectionLocationId = string.IsNullOrWhiteSpace(model.CollectPostcode)
                                ? model.CollectionLocationId
                                : privateAddressLocationId;

            var deliverToLocationId = string.IsNullOrWhiteSpace(model.DeliverToPostcode)
                                ? model.DeliverToLocationId
                                : privateAddressLocationId;

            return(new RunLog
            {
                RunLogType = "M",
                CreatedByUserID = model.CreatedByUserId,
                CreateDate = DateTime.Now,
                DutyDate = dutyDate,
                CollectionLocationID = collectionLocationId,
                CollectionPostcode = model.CollectPostcode,
                CollectDateTime = collectDateTime,
                DeliverDateTime = deliverDateTime,
                ControllerMemberID = model.ControllerMemberId,
                Urgency = 2,
                Notes = model.Notes,
                OriginLocationID = collectionLocationId,
                CallFromLocationID = 42,
                RiderMemberID = model.RiderMemberId,
                DeliverToLocationID = deliverToLocationId,
                DeliverToPostcode = model.DeliverToPostcode,
                FinalDestinationLocationID = deliverToLocationId,
                HomeSafeDateTime = homeSafe,
                Boxes = model.BoxQty
            });
        }