예제 #1
0
        public async Task <ResponseViewModel <GenericResponseModel> > UpdateTruckOnWarehouseCheck(TheoryWeighValueModel theoryWeighValueModel)
        {
            ResponseViewModel <GenericResponseModel> response = new ResponseViewModel <GenericResponseModel>();

            try
            {
                var gatePass = await _gatePassRepository.GetAsync(gt => gt.ID == theoryWeighValueModel.gatePassID && gt.isDelete == false, QueryIncludes.GATEPASSFULLINCLUDES);

                if (gatePass == null)
                {
                    return(response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false));
                }
                else
                {
                    switch (gatePass.stateID)
                    {
                    case GatepassState.STATE_FINISH_WEIGHT_IN:
                        return(await this.UpdateTruckOnWarehouseCheckIn(theoryWeighValueModel));

                    case GatepassState.STATE_FINISH_WAREHOUSE_CHECK_IN:
                        return(await this.UpdateTruckOnWarehouseCheckOut(theoryWeighValueModel));

                    default:
                        return(response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false));
                    }
                }
            }
            catch (Exception)
            {
                return(response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false));
            }
        }
예제 #2
0
        public async Task <ResponseViewModel <WeightRecordViewModel> > UpdateWeightValue(WeightDataViewModel weightDataViewModel)
        {
            ResponseViewModel <WeightRecordViewModel> response = new ResponseViewModel <WeightRecordViewModel>();

            try
            {
                WeightRecord weightRecord = new WeightRecord();
                Random       r            = new Random();
                //if (await _authService.CheckUserPermission(weightDataViewModel.employeeID, weightDataViewModel.employeeRFID, "UpdateWeightValue"))
                //{
                var weighNum = await _weightRecordRepository.GetManyAsync(wt => wt.gatepassID == weightDataViewModel.gatePassID && wt.isDelete == false);

                weightRecord.code          = r.Next().ToString();
                weightRecord.gatepassID    = weightDataViewModel.gatePassID;
                weightRecord.isDelete      = false;
                weightRecord.weighBridgeID = weightDataViewModel.weighBridgeID;
                weightRecord.weighBridge   = await _weighBridgeRepository.GetByIdAsync(weightDataViewModel.weighBridgeID);

                weightRecord.weightEmployeeID = weightDataViewModel.employeeID;
                weightRecord.employee         = await _employeeRepository.GetByIdAsync(weightDataViewModel.employeeID);

                weightRecord.weightTime                 = DateTime.Now;
                weightRecord.weightValue                = weightDataViewModel.weightValue;
                weightRecord.frontCameraCapturePath     = Constant.TruckCapturePath + weightDataViewModel.fontCameraName;
                weightRecord.gearCameraCapturePath      = Constant.TruckCapturePath + weightDataViewModel.gearCameraName;
                weightRecord.cabinCameraCapturePath     = Constant.TruckCapturePath + weightDataViewModel.cabinCameraName;
                weightRecord.containerCameraCapturePath = Constant.TruckCapturePath + weightDataViewModel.containerCameraName;
                weightRecord.weightNo = weighNum.Count() + 1;
                var gatePass = await _gatePassRepository.GetAsync(gt => gt.ID == weightDataViewModel.gatePassID && gt.isDelete == false);

                if (gatePass.stateID == GatepassState.STATE_FINISH_SECURITY_CHECK_IN)
                {
                    gatePass.stateID = GatepassState.STATE_FINISH_WEIGHT_IN;
                }
                else if (gatePass.stateID == GatepassState.STATE_FINISH_WAREHOUSE_CHECK_OUT)
                {
                    gatePass.stateID = GatepassState.STATE_FINISH_WEIGHT_OUT;
                }
                _gatePassRepository.Update(gatePass);
                _weightRecordRepository.Add(weightRecord);
                if (await _unitOfWork.SaveChangesAsync())
                {
                    response = ResponseConstructor <WeightRecordViewModel> .ConstructBoolRes(ResponseCode.SUCCESS, true);
                }
                else
                {
                    response = ResponseConstructor <WeightRecordViewModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false);
                }
                //}
                //else
                //{
                //    response = ResponseConstructor<WeightRecordViewModel>.ConstructBoolRes(ResponseCode.ERR_WEI_WEIGH_NOT_PERMITTED, false);
                //}
                return(response);
            }
            catch (Exception)
            {
                return(response = ResponseConstructor <WeightRecordViewModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false));
            }
        }
예제 #3
0
        public async Task <ResponseViewModel <GenericResponseModel> > UpdateTruckOnWarehouseCheckIn(TheoryWeighValueModel theoryWeighValueModel)
        {
            ResponseViewModel <GenericResponseModel> response = new ResponseViewModel <GenericResponseModel>();

            try
            {
                if (await _authService.CheckUserPermission(theoryWeighValueModel.employeeID, theoryWeighValueModel.employeeRFID, "UpdateTruckOnWarehouseCheckIn"))
                {
                    var gatePass = await _gatePassRepository.GetAsync(gt => gt.ID == theoryWeighValueModel.gatePassID && gt.isDelete == false);

                    if (gatePass == null)
                    {
                        response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_QUE_NO_GATEPASS_FOUND, false);
                    }
                    else
                    {
                        if (gatePass.stateID == GatepassState.STATE_FINISH_WEIGHT_IN)
                        {
                            gatePass.stateID = GatepassState.STATE_FINISH_WAREHOUSE_CHECK_IN;
                            var queue = await _queueListRepository.GetAsync(qu => qu.gatePassID == gatePass.ID);

                            var lane = await _laneRepository.GetAsync(ln => ln.ID == queue.laneID);

                            lane.usingStatus = LaneStatus.OCCUPIED;
                            _laneRepository.Update(lane);
                            _gatePassRepository.Update(gatePass);
                            if (await _unitOfWork.SaveChangesAsync())
                            {
                                response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.SUCCESS, true);
                            }
                            else
                            {
                                response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false);
                            }
                        }
                        else
                        {
                            response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_QUE_GATEPASS_WRONG_STATE, false);
                        }
                    }
                }
                else
                {
                    response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_USER_PERMISSION, false);
                }
                return(response);
            }
            catch (Exception)
            {
                return(response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false));
            }
        }
예제 #4
0
        public ResponseViewModel <WeightRecordViewModel> AddTruckCamera(string fileName, byte[] fileContent)
        {
            ResponseViewModel <WeightRecordViewModel> response = new ResponseViewModel <WeightRecordViewModel>();
            string filePath = Constant.DriverCapturePath + fileName;

            // Write to file
            if (fileName == null || fileContent == null)
            {
                response = ResponseConstructor <WeightRecordViewModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false);
            }
            else
            {
                File.WriteAllBytes(filePath, fileContent);
                response = ResponseConstructor <WeightRecordViewModel> .ConstructBoolRes(ResponseCode.SUCCESS, true);
            }
            return(response);
        }
예제 #5
0
        public async Task <ResponseViewModel <GenericResponseModel> > UpdateTheoryWeighValue(TheoryWeighValueModel theoryWeighValueModel)
        {
            ResponseViewModel <GenericResponseModel> response = new ResponseViewModel <GenericResponseModel>();

            try
            {
                if (await _authService.CheckUserPermission(theoryWeighValueModel.employeeID, theoryWeighValueModel.employeeRFID, "UpdateTheoryWeighValue"))
                {
                    var gatePass = await _gatePassRepository.GetAsync(gt => gt.ID == theoryWeighValueModel.gatePassID && gt.isDelete == false);

                    if (gatePass == null)
                    {
                        response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_QUE_NO_GATEPASS_FOUND, false);
                    }
                    else
                    {
                        gatePass.theoryWeightValue = theoryWeighValueModel.theoryWeighValue;
                        _gatePassRepository.Update(gatePass);
                        if (await _unitOfWork.SaveChangesAsync())
                        {
                            response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.SUCCESS, true);
                        }
                        else
                        {
                            response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false);
                        }
                    }
                }
                else
                {
                    response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_USER_PERMISSION, false);
                }
                return(response);
            }
            catch (Exception)
            {
                return(response = ResponseConstructor <GenericResponseModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false));
            }
        }
예제 #6
0
        public async Task <ResponseViewModel <QueueListViewModel> > CallNextTruck(int truckGroupID)
        {
            ResponseViewModel <QueueListViewModel> response = new ResponseViewModel <QueueListViewModel>();
            var queues = await _queueListRepository.GetManyAsync(qu => qu.gatePass.truckGroupID == truckGroupID && qu.isDelete == false, QueryIncludes.QUEUELISTFULLINCLUDES);

            var firstqueue = queues.OrderBy(q => q.queueNumber).First();
            var gatePass   = await _gatePassRepository.GetAsync(gt => gt.ID == firstqueue.gatePassID && gt.isDelete == false, QueryIncludes.GATEPASSFULLINCLUDES);

            if (gatePass == null)
            {
                response = ResponseConstructor <QueueListViewModel> .ConstructBoolRes(ResponseCode.ERR_QUE_NO_QUEUE_FOUND, false);
            }
            else
            {
                // Change GatePass state
                switch (gatePass.stateID)
                {
                case GatepassState.STATE_REGISTERED:
                    gatePass.stateID = GatepassState.STATE_CALLING_1;
                    break;

                case GatepassState.STATE_CALLING_1:
                    gatePass.stateID = GatepassState.STATE_CALLING_2;
                    break;

                case GatepassState.STATE_CALLING_2:
                    gatePass.stateID = GatepassState.STATE_CALLING_3;
                    break;

                case GatepassState.STATE_CALLING_3:
                    // Update state & Update queueList
                    gatePass.stateID = GatepassState.STATE_REGISTERED;
                    var currentQueue = await _queueListRepository.GetAsync(qu => qu.gatePassID == gatePass.ID && qu.isDelete == false);

                    var queueList = await _queueListRepository.GetManyAsync(qu => qu.queueNumber > currentQueue.queueNumber && qu.queueNumber <= (currentQueue.queueNumber + 5) && qu.gatePass.truckGroup.ID == gatePass.truckGroup.ID && qu.isDelete == false);

                    // If there are less than 5 - move to the last
                    if (queueList.Count() < 5)
                    {
                        // Set new Order
                        currentQueue.queueNumber += queueList.Count();
                        // Shift up 1 item for orther QueueItem
                        foreach (var queueItem in queueList)
                        {
                            queueItem.queueNumber -= 1;
                            _queueListRepository.Update(queueItem);
                        }
                    }
                    else      // If more than 5 - move down 5
                    {
                        // Set new order
                        currentQueue.queueNumber += 5;
                        // Shift up 1 item for orther QueueItem
                        foreach (var queueItem in queueList)
                        {
                            queueItem.queueNumber -= 1;
                            _queueListRepository.Update(queueItem);
                        }
                    }
                    break;

                default:
                    return(response = ResponseConstructor <QueueListViewModel> .ConstructBoolRes(ResponseCode.ERR_QUE_NO_QUEUE_FOUND, false));
                }
                _gatePassRepository.Update(gatePass);
                if (await _unitOfWork.SaveChangesAsync())
                {
                    response = ResponseConstructor <QueueListViewModel> .ConstructBoolRes(ResponseCode.SUCCESS, true);
                }
                else
                {
                    response = ResponseConstructor <QueueListViewModel> .ConstructBoolRes(ResponseCode.ERR_SEC_UNKNOW, false);
                }
            }
            return(response);
        }