示例#1
0
        public Task SendAsync(DispatchViewModel model)
        {
            var dispatchMessage = model.ToDispatchMessage();

            _logger.LogInformation($"Sending dispatch message {dispatchMessage}...");

            return(_messageBus.PublishAsync(dispatchMessage));
        }
        public async Task <IActionResult> Dispatch(int id, DispatchViewModel model)
        {
            if (!HasPermission("DISPATCH"))
            {
                return(Unauthorized());
            }

            var booking = await _context.Bookings
                          .Include(b => b.Customer)
                          .Include(b => b.Invoice)
                          .Include(b => b.Package)
                          .Include(b => b.Package.PackageType)
                          .Include(b => b.Package.PackageLogs)
                          .Include(b => b.Service)
                          .SingleAsync(m => m.Id == id);

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

            int userId = GetCurrentUserId();

            if (ModelState.IsValid)
            {
                booking.Package.AssignedToUserId = model.UserId;

                //XXX:TODO Fix when couriers are able to receive packages to their personal inventory
                // Update status to OutForDelivery when the courier has confirmed receipt of the package
                // For now, set as out for delivery when package is dispatched to courier
                //booking.Package.Status = PackageStatus.DispatchedToCourier;
                booking.Package.Status = PackageStatus.OutForDelivery;

                var packageLog = new PackageLog()
                {
                    PackageId = booking.Package.BookingId,
                    //XXX:TODO See comment above
                    //LogMessage = "Dispatched To Courier",
                    LogMessage = string.Format("Received By Courier {0}.", model.UserId),
                    LoggedAt   = DateTime.Now
                };

                booking.Package.PackageLogs.Add(packageLog);

                _context.Update(booking);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Bookings", new { id = booking.Id }));
            }

            ViewData["UserId"] = new SelectList(_context.Users, "Id", "UserName");

            return(View(model));
        }
示例#3
0
        public async Task <IActionResult> Post([FromBody] DispatchViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _service.SendAsync(model);

            return(Ok());
        }
示例#4
0
        // GET: Dispatch/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var obj      = new DispatchViewModel();
            var url      = "api/dispatch/getbyid/" + id;
            var response = await HttpClientHelper.ApiCall(url, Method.GET);

            if (response.IsSuccessful)
            {
                var result = response.Content;
                obj = JsonConvert.DeserializeObject <DispatchViewModel>(result);
            }

            return(PartialView(obj));
        }
        public static DispatchViewModel BindDispatchViewModelBinder(Dispatch dispatch)
        {
            var dispatchViewModel = new DispatchViewModel();
            var dispatchDetail    = dispatch.DispatchDetails.FirstOrDefault();

            dispatchViewModel.BidNumber            = dispatch.BidNumber;
            dispatchViewModel.DispatchDate         = dispatch.DispatchDate;
            dispatchViewModel.DispatchID           = dispatch.DispatchID;
            dispatchViewModel.DispatchedByStoreMan = dispatch.DispatchedByStoreMan;
            dispatchViewModel.DriverName           = dispatch.DriverName;
            dispatchViewModel.FDP             = dispatch.FDP.Name;
            dispatchViewModel.GIN             = dispatch.GIN;
            dispatchViewModel.Month           = dispatch.PeriodMonth;
            dispatchViewModel.PlateNo_Prime   = dispatch.PlateNo_Prime;
            dispatchViewModel.PlateNo_Trailer = dispatch.PlateNo_Trailer;
            //dispatchViewModel.Program = dispatch.program;

            dispatchViewModel.Remark        = dispatch.Remark;
            dispatchViewModel.RequisitionNo = dispatch.RequisitionNo;
            dispatchViewModel.Round         = dispatch.Round;

            dispatchViewModel.Type = dispatch.Type;
            dispatchViewModel.WeighBridgeTicketNumber = dispatch.WeighBridgeTicketNumber;
            dispatchViewModel.Year = dispatch.PeriodYear;
            if (dispatch.DispatchAllocation.ShippingInstruction != null)
            {
                dispatchViewModel.SINumber = dispatch.DispatchAllocation.ShippingInstruction.Value;
            }
            if (dispatch.DispatchAllocation.ProjectCode != null)
            {
                dispatchViewModel.ProjectNumber = dispatch.DispatchAllocation.ProjectCode.Value;
            }
            //if (dispatchDetail != null)
            //{
            //    dispatchViewModel.CommodityID = dispatchDetail.CommodityID;
            //    dispatchViewModel.Commodity = dispatchDetail.Commodity.Name;

            //}
            if (dispatch.DispatchAllocationID.HasValue)
            {
                dispatchViewModel.DispatchAllocationID = dispatch.DispatchAllocationID.Value;
            }
            return(dispatchViewModel);
        }
示例#6
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,ItemId,ProductId,WarehouseId,DeliveryRequestId")] DispatchViewModel dispatchViewModel)
        {
            var url      = "api/dispatch/update";
            var response = await HttpClientHelper.ApiCall(url, Method.PUT, dispatchViewModel);

            if (response.IsSuccessful)
            {
                TempData["Message"] = "Successfully Updated";
                return(RedirectToAction("Index"));
            }
            else
            {
                Error("An error has occurred");
                Log.Error(string.Format(Type.GetType(typeof(DispatchViewModel).Name) + "||Edit||Dispatch ID::{0}||API Response::{1}", dispatchViewModel.Id, response));
                return(RedirectToAction("Index"));
            }

            //ViewBag.DeliveryRequestId = new SelectList(db.DeliveryRequestViewModels, "Id", "Requestor", dispatchViewModel.DeliveryRequestId);
            //ViewBag.ItemId = new SelectList(db.ItemViewModels, "Id", "Description", dispatchViewModel.ItemId);
            //ViewBag.ProductId = new SelectList(db.ProductViewModels, "Id", "Description", dispatchViewModel.ProductId);
            //ViewBag.WarehouseId = new SelectList(db.WarehouseViewModels, "Id", "WarehouseCode", dispatchViewModel.WarehouseId);0-
        }
示例#7
0
        public List <DispatchViewModel> GetAllTransportersWithoutGrn()
        {
            var dispatchAllocationIds =
                _unitOfWork.DispatchAllocationRepository.GetAll().Select(t => t.DispatchAllocationID).ToList();
            var dispatches =
                _unitOfWork.DispatchRepository.Get(t => dispatchAllocationIds.Contains(t.DispatchAllocationID.Value),
                                                   null, "DispatchDetails")
                .ToList();

            List <DispatchViewModel> dispatchViewModels = new List <DispatchViewModel>();

            foreach (var dispatch in dispatches)
            {
                var dispatchViewModel = new DispatchViewModel();
                dispatchViewModel.DispatchID   = dispatch.DispatchID;
                dispatchViewModel.DispatchDate = dispatch.DispatchDate;
                dispatchViewModel.Transporter  = dispatch.Transporter.Name;
                dispatchViewModel.BidNumber    = dispatch.BidNumber;
                dispatchViewModel.FDP          = dispatch.FDP.Name;
                dispatchViewModels.Add(dispatchViewModel);
            }
            return(dispatchViewModels);
        }
示例#8
0
        public ActionResult EditDisp(DispatchViewModel dispatchModel)
        {
            try
            {
                var regService  = new RegistrationService();
                var service     = ServiceCreator.GetManagerService(User.Identity.Name);
                var dispService = ServiceCreator.GetDispatchesService();

                var config = regService.FindConfiguration(User.Identity.Name);
                var dispId = Guid.NewGuid();
                var disp   = new Dispatch {
                    Host = config.TelegramBotLocation, Id = dispId, Message = dispatchModel.Message, Name = dispatchModel.Name, AccountId = config.AccountId, Done = false
                };
                dispService.CreateDispatch(disp);

                var allTables = service.GetInActiveTables();
                var allChats  = new List <long>();
                allTables.ForEach(o => { if (!allChats.Contains(o.ChatId))
                                         {
                                             allChats.Add(o.ChatId);
                                         }
                                  });
                foreach (var chat in allChats)
                {
                    var dispMes = new DispatchMessage {
                        DispatchId = dispId, ChatId = chat, Id = Guid.NewGuid(), Send = false
                    };
                    dispService.CreateDispatchMessage(dispMes);
                }

                return(Json(new { isAuthorized = true, isSuccess = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { isAuthorized = true, isSuccess = false, error = ex.Message }));
            }
        }
示例#9
0
        public ActionResult Index1()
        {
            DispatchViewModel model = new DispatchViewModel();

            model.Dispatchs = new List <Dispatch>();

            if (ConfigurationManager.AppSettings["IsDemo"] == "true")
            {
                #region demo data

                model.Dispatchs.Add(new Dispatch
                {
                    BeatNumber                = "221",
                    TruckNumber               = "390",
                    ContractorName            = "ABC Towing",
                    DriverName                = "John Smith",
                    ServiceDate               = "8/1/2012",
                    BeatStartTime             = "05:30:30",
                    Status                    = "10-8",
                    Alarms                    = "-",
                    LastUpdateTime            = "07:31:30",
                    Freeway                   = "SR 22",
                    Direction                 = "EB",
                    LastLocation              = "Between Euclid St. and Harbor Blvd.",
                    AssistDescription         = "-",
                    IncidentCode              = "1124",
                    ServiceCode               = "B",
                    VehicleDescription        = "Black Sedan",
                    VehicleLicensePlateNumber = "KCS220",
                    TowLocation               = "-",
                    IsVisible                 = true
                });

                model.Dispatchs.Add(new Dispatch
                {
                    BeatNumber                = "222",
                    TruckNumber               = "390",
                    ContractorName            = "ABC Towing",
                    DriverName                = "George Jones",
                    ServiceDate               = "8/1/2012",
                    BeatStartTime             = "00:30:30",
                    Status                    = "10-8",
                    Alarms                    = "Speeding",
                    LastUpdateTime            = "07:31:38",
                    Freeway                   = "SR 22",
                    Direction                 = "EB",
                    LastLocation              = "Between Euclid St. and Harbor Blvd.",
                    AssistDescription         = "-",
                    IncidentCode              = "1",
                    ServiceCode               = "1",
                    VehicleDescription        = "White SUV",
                    VehicleLicensePlateNumber = "UVW123",
                    TowLocation               = "-",
                    IsVisible                 = true
                });

                #endregion
            }
            else
            {
                //call db or service
            }

            return(View(model));
        }
        public DispatchViewModel CreateDispatchFromDispatchAllocation(Guid dispatchAllocationId, decimal quantityInUnit)
        {
            var dispatchAllocation = _unitOfWork.DispatchAllocationRepository.FindById(dispatchAllocationId);

            var dispatch = new DispatchViewModel();

            dispatch.BidNumber            = dispatchAllocation.BidRefNo;
            dispatch.CreatedDate          = DateTime.Today;
            dispatch.DispatchAllocationID = dispatchAllocation.DispatchAllocationID;
            dispatch.DispatchDate         = DateTime.Today;
            //dispatch.DispatchID = Guid.NewGuid();
            dispatch.DispatchedByStoreMan = string.Empty;
            dispatch.DriverName           = string.Empty;
            dispatch.FDPID = dispatchAllocation.FDPID;
            dispatch.GIN   = string.Empty;
            dispatch.HubID = dispatchAllocation.HubID;
            if (dispatchAllocation.ProgramID.HasValue)
            {
                dispatch.ProgramID = dispatchAllocation.ProgramID.Value;
            }
            if (dispatchAllocation.Month.HasValue)
            {
                dispatch.Month = dispatchAllocation.Month.Value;
            }
            if (dispatchAllocation.Year.HasValue)
            {
                dispatch.Year = dispatchAllocation.Year.Value;
            }
            dispatch.PlateNo_Prime   = string.Empty;
            dispatch.PlateNo_Trailer = string.Empty;
            dispatch.Remark          = string.Empty;
            dispatch.RequisitionNo   = dispatchAllocation.RequisitionNo;
            dispatch.RequisitionId   = dispatchAllocation.RequisitionId;
            dispatch.ProgramID       = dispatchAllocation.ProgramID.HasValue?dispatchAllocation.ProgramID.Value:0;
            if (dispatchAllocation.Round.HasValue)
            {
                dispatch.Round = dispatchAllocation.Round.Value;
            }
            if (dispatchAllocation.TransporterID.HasValue)
            {
                dispatch.TransporterID = dispatchAllocation.TransporterID.Value;
            }

            dispatch.WeighBridgeTicketNumber = string.Empty;

            //  Dispatch dispatchDetail = new DispatchDetail();

            var parentCommodityId =
                _unitOfWork.CommodityRepository.FindById(dispatchAllocation.CommodityID).ParentID ??
                dispatchAllocation.CommodityID;


            dispatch.CommodityID      = parentCommodityId;
            dispatch.CommodityChildID = dispatchAllocation.CommodityID;
            dispatch.Commodity        = dispatchAllocation.Commodity.Name;
            //dispatch.DispatchDetailID = Guid.NewGuid();
            dispatch.DispatchID            = dispatch.DispatchID;
            dispatch.Quantity              = 0;
            dispatch.QuantityInUnit        = 0;
            dispatch.UnitID                = dispatchAllocation.Unit;
            dispatch.ShippingInstructionID = dispatchAllocation.ShippingInstructionID;
            dispatch.ProjectCodeID         = dispatchAllocation.ProjectCodeID;
            // dispatch.PartitionId = 0;

            //dispatch.DispatchDetails.Add(dispatchDetail);
            dispatch.plannedAmount = dispatchAllocation.Amount;
            return(dispatch);
        }
示例#11
0
        private List <DispatchViewModel> MapDispatchToDispatchViewModel(List <Dispatch> dispatches)
        {
            List <DispatchViewModel> dispatchViewModels = new List <DispatchViewModel>();

            foreach (var dispatch in dispatches)
            {
                var id1 = dispatch.DispatchAllocationID.Value;
                var dispatchAllocation =
                    _unitOfWork.DispatchAllocationRepository.Get(t => t.DispatchAllocationID == id1, null, "Program").
                    FirstOrDefault();

                var dispatchViewModel = new DispatchViewModel();
                dispatchViewModel.BidNumber   = dispatch.BidNumber;
                dispatchViewModel.CreatedDate = dispatch.CreatedDate;

                dispatchViewModel.DispatchAllocationID = dispatch.DispatchAllocationID.Value;
                dispatchViewModel.DispatchDate         = dispatch.DispatchDate;
                dispatchViewModel.DispatchID           = dispatch.DispatchID;
                dispatchViewModel.DispatchedByStoreMan = dispatch.DispatchedByStoreMan;
                dispatchViewModel.DriverName           = dispatch.DriverName;
                if (dispatch.FDPID.HasValue)
                {
                    dispatchViewModel.FDPID = dispatch.FDPID.Value;
                }
                dispatchViewModel.FDP    = dispatch.FDP.Name;
                dispatchViewModel.Region = dispatch.FDP.AdminUnit.AdminUnit2.AdminUnit2.Name;
                dispatchViewModel.Zone   = dispatch.FDP.AdminUnit.AdminUnit2.Name;
                dispatchViewModel.Woreda = dispatch.FDP.AdminUnit.Name;
                dispatchViewModel.GIN    = dispatch.GIN;
                dispatchViewModel.HubID  = dispatch.HubID;
                // dispatch.ProgramID = dispatchAllocation.ProgramID;
                dispatchViewModel.Program = dispatchAllocation.Program.Name;

                dispatchViewModel.Month = dispatch.PeriodMonth;

                dispatchViewModel.Year            = dispatch.PeriodYear;
                dispatchViewModel.PlateNo_Prime   = dispatch.PlateNo_Prime;
                dispatchViewModel.PlateNo_Trailer = dispatch.PlateNo_Trailer;
                dispatchViewModel.Remark          = dispatch.Remark;
                dispatchViewModel.RequisitionNo   = dispatch.RequisitionNo;
                dispatchViewModel.ProgramID       = dispatchAllocation.ProgramID.HasValue
                                                  ? dispatchAllocation.ProgramID.Value
                                                  : 0;

                dispatchViewModel.Round = dispatch.Round;

                dispatchViewModel.TransporterID = dispatch.TransporterID;

                dispatchViewModel.WeighBridgeTicketNumber = dispatch.WeighBridgeTicketNumber;

                var dispatchDetail = dispatch.DispatchDetails.FirstOrDefault();
                dispatchViewModel.CommodityID = dispatchDetail.CommodityID;
                dispatchViewModel.Commodity   = dispatchDetail.Commodity.Name;
                //dispatch.DispatchDetailID = Guid.NewGuid();
                dispatchViewModel.DispatchID            = dispatchDetail.DispatchID;
                dispatchViewModel.Quantity              = dispatchDetail.RequestedQuantityInMT;
                dispatchViewModel.QuantityInUnit        = dispatchDetail.RequestedQunatityInUnit;
                dispatchViewModel.UnitID                = dispatchDetail.UnitID;
                dispatchViewModel.ShippingInstructionID = dispatchAllocation.ShippingInstructionID;
                dispatchViewModel.ProjectCodeID         = dispatchAllocation.ProjectCodeID;


                dispatchViewModels.Add(dispatchViewModel);
            }
            return(dispatchViewModels);
        }