Exemplo n.º 1
0
        public async Task <ActionResult> DownLoadExcel()
        {
            //直接從MongoDB擷取
            var trackLog = await _traceService.GetTrace(SessionSearchTraceModel);

            var convertList = _traceService.ConvertToTraceView(trackLog, SessionSearchTraceModel.DriverId, SessionSearchTraceModel.VehicleId);

            string searchText = string.Format("軌跡查詢條件:起訖時間({0}~{1})", SessionSearchTraceModel.BeginDateTime, SessionSearchTraceModel.EndDateTime);

            if (!string.IsNullOrEmpty(SessionSearchTraceModel.DriverId))
            {
                var queryDriver = _aspNetUsersService.GetUserModel(SessionSearchTraceModel.DriverId);
                if (queryDriver != null)
                {
                    searchText += string.Format(", 司機({0})", queryDriver.RealName);
                }
            }

            if (SessionSearchTraceModel.VehicleId.HasValue)
            {
                var queryVehicle = _vehicleService.GetVehicle(SessionSearchTraceModel.VehicleId.Value);
                if (queryVehicle != null)
                {
                    searchText += string.Format(", 車牌號碼({0})", queryVehicle.LicenseNumber);
                }
            }

            string searchDateStr = "軌跡查詢_" + SessionSearchTraceModel.BeginDateTime.ToString("MMddHHmm") + "_" + SessionSearchTraceModel.EndDateTime.ToString("MMddHHmm");
            var    fileStream    = _traceService.GenerateXlsx(convertList, "軌跡查詢", searchText, searchDateStr + ".xlsx");

            return(File(fileStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "QueryTrace.xlsx"));
        }
        public ActionResult EditAccount(string UserId)
        {
            UserModel data = new UserModel();

            data = _aspNetUsersService.GetUserModel(UserId);
            CommonDropDownList(false);
            return(View(data));
        }
        public async Task <JsonResult> Quote(DriverQuotePriceViewModel Model)
        {
            _logger.Information($"Quote : { JsonConvert.SerializeObject(Model)}");

            ResponseViewModel responseResult = new ResponseViewModel();

            try
            {
                var user = _aspNetUsersService.GetUserModelByName(User.Identity.Name);
                responseResult = await _bookingService.CreateOrUpdateQuotedRecords(Model, user.Id, null);

                if (responseResult.IsOk)
                {
                    #region 報價推播通知
                    var    queryDriver       = _aspNetUsersService.GetUserModel(Model.DriverId);
                    string appellationDriver = string.Empty;
                    if (!string.IsNullOrEmpty(queryDriver.Sex))
                    {
                        appellationDriver = StringExt.AppellationName(queryDriver.RealName, queryDriver.Sex.Trim());
                    }
                    else
                    {
                        appellationDriver = queryDriver.RealName;
                    }

                    string title        = Resource.Driver + appellationDriver + string.Format(Resource.QuotedPrice, Model.QuotedPrice);
                    string body         = string.Empty;
                    string goodsOwnerId = _bookingService.GetBooking(Model.MessageId).GoodOwnerId;

                    PushMessageViewModel pushMsg = RunPushApi(title, body, user.Id, goodsOwnerId, 10, Model.MessageId.ToString());
                    await RunPushApiAsync(pushMsg);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                _logger.Information($"Quote exception: { JsonConvert.SerializeObject(ex)}");
                responseResult.IsOk    = false;
                responseResult.Message = ex.ToString();
                throw ex;
            }
            return(Json(responseResult, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Save(BookingQuoteCollection model, HttpPostedFileBase[] goodsPhotoUpload)
        {
            VerityBookingResult result = new VerityBookingResult();

            if (ModelState.IsValid)
            {
                try
                {
                    var user = _aspNetUsersService.GetUserModelByName(User.Identity.Name);
                    result = await _bookingService.UpdateBookingQuote(model, user.Id, user.CompanyId);

                    if (result.IsOk)
                    {
                        int count = 1;
                        if (goodsPhotoUpload != null)
                        {
                            foreach (HttpPostedFileBase file in goodsPhotoUpload)
                            {
                                VerityResult uploadResult = new VerityResult();
                                bool         isUpload     = FileUploadVerify(file);
                                if (isUpload)
                                {
                                    uploadResult = await UploadImageFile(file, result.GoodOwnerId, result.MessageId, count);
                                }

                                count++;
                            }
                        }

                        TempData["SaveResult"] = result.Message;

                        #region 推播通知原車主取消、新車主新任務
                        //原車主
                        var    queryOriginDriver = _aspNetUsersService.GetUserModel(model.DriverQuotePrice.OldDriverId);
                        string originDriver      = string.Empty;
                        if (!string.IsNullOrEmpty(queryOriginDriver.Sex))
                        {
                            originDriver = StringExt.AppellationName(queryOriginDriver.RealName, queryOriginDriver.Sex.Trim());
                        }
                        else
                        {
                            originDriver = queryOriginDriver.RealName;
                        }

                        string title = "原" + Resource.Driver + originDriver + MessageResource.CancelMission;
                        string body  = string.Empty;

                        PushMessageViewModel pushMsg = RunPushApi(title, body, user.Id, model.DriverQuotePrice.OldDriverId, 10, model.Booking.MessageId.ToString());
                        await RunPushApiAsync(pushMsg);

                        //新車主
                        var    queryNewDriver = _aspNetUsersService.GetUserModel(model.DriverQuotePrice.DriverId);
                        string newDriver      = string.Empty;
                        if (!string.IsNullOrEmpty(queryNewDriver.Sex))
                        {
                            newDriver = StringExt.AppellationName(queryNewDriver.RealName, queryNewDriver.Sex.Trim());
                        }
                        else
                        {
                            newDriver = queryNewDriver.RealName;
                        }

                        string newTitle = "新" + Resource.Driver + newDriver + MessageResource.HadNewMission;
                        string newBody  = string.Empty;

                        PushMessageViewModel newPushMsg = RunPushApi(newTitle, newBody, user.Id, model.DriverQuotePrice.DriverId, 10, model.Booking.MessageId.ToString());
                        await RunPushApiAsync(newPushMsg);

                        #endregion

                        #region 推播通知貨主變更司機
                        //貨主
                        var    queryGoodsOwner = _aspNetUsersService.GetUserModel(model.Booking.GoodOwnerId);
                        string goodsOwner      = string.Empty;
                        if (!string.IsNullOrEmpty(queryGoodsOwner.Sex))
                        {
                            goodsOwner = StringExt.AppellationName(queryGoodsOwner.RealName, queryGoodsOwner.Sex.Trim());
                        }
                        else
                        {
                            goodsOwner = queryNewDriver.RealName;
                        }

                        string forgoodsOwnerTitle = "原" + Resource.Driver + originDriver + "變更為新" + Resource.Driver + newDriver;
                        PushMessageViewModel goodsOwnerPushMsg = RunPushApi(forgoodsOwnerTitle, null, user.Id, model.Booking.GoodOwnerId, 10, model.Booking.MessageId.ToString());
                        await RunPushApiAsync(goodsOwnerPushMsg);

                        #endregion

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["SaveResult"] = result.Message;
                    }
                }
                catch (Exception ex)
                {
                    TempData["SaveResult"] = result.Message;
                    _logger.Information($"Save BookingViewModel error : { JsonConvert.SerializeObject(ex)}");
                    throw ex;
                }
            }
            return(View("Create", model));
        }
Exemplo n.º 5
0
        public ActionResult DownLoadExcel(string TabType)
        {
            BookingReportMonthCollection data = new BookingReportMonthCollection();

            DateTime parsedYearMonth = DateTime.Parse(SessionBookingReportMonthSearchModel.SearchYearMonth);

            SessionBookingReportMonthSearchModel.SearchYear  = parsedYearMonth.Year;
            SessionBookingReportMonthSearchModel.SearchMonth = parsedYearMonth.Month;

            string companyName = string.Empty;

            if (SessionBookingReportMonthSearchModel.SearchCompanyId.HasValue)
            {
                var queryCompany = _companyService.GetCompanyName(SessionBookingReportMonthSearchModel.SearchCompanyId.Value);
                if (!string.IsNullOrEmpty(queryCompany))
                {
                    companyName = queryCompany;
                }
            }

            string licenseNumber = string.Empty;

            if (SessionBookingReportMonthSearchModel.SearchVehicleId.HasValue)
            {
                var queryVehicle = _vehicleService.QueryVehicle(SessionBookingReportMonthSearchModel.SearchVehicleId.Value);
                licenseNumber = queryVehicle.LicenseNumber;
            }

            string driverName = string.Empty;

            if (!string.IsNullOrEmpty(SessionBookingReportMonthSearchModel.SearchDriverId))
            {
                var queryDriver = _aspNetUsersService.GetUserModel(SessionBookingReportMonthSearchModel.SearchDriverId);
                driverName = queryDriver.RealName;
            }

            string customerName = string.Empty;

            if (!string.IsNullOrEmpty(SessionBookingReportMonthSearchModel.SearchGoodOwnerId))
            {
                var queryCustomer = _aspNetUsersService.GetUserModel(SessionBookingReportMonthSearchModel.SearchGoodOwnerId);
                customerName = queryCustomer.RealName;
            }

            string tabTypeName = string.Empty;

            switch (TabType)
            {
            case "Driver":
                tabTypeName = "司機";
                break;

            case "Customer":
                tabTypeName = "客戶";
                break;

            case "Vehicle":
                tabTypeName = "車輛";
                break;
            }

            string searchText = string.Format("月報表({0})查詢條件:查詢月份({1}),車行({2}),車號({3}),車主({4}),客戶({5})",
                                              tabTypeName,
                                              SessionBookingReportMonthSearchModel.SearchYear + "/" + SessionBookingReportMonthSearchModel.SearchMonth,
                                              companyName, licenseNumber, driverName, customerName);

            data = _bookingService.GetBookingReportMonthCollection(SessionBookingReportMonthSearchModel);

            string searchDateStr = "月報表_" + DateTime.Now.ToString("yyyyMMddHHmm");
            var    fileStream    = _bookingService.GenerateMonthReportXlsx(data, TabType, "月報表_" + tabTypeName, searchText, searchDateStr + ".xlsx");

            return(File(fileStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "QueryOrderData.xlsx"));
        }