public async Task <ActionResult> Save(BookingViewModel model, HttpPostedFileBase[] goodsPhotoUpload)
        {
            VerityBookingResult result = new VerityBookingResult();

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

                    if (result.IsOk)
                    {
                        int count = 1;
                        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 推播
                        if (!string.IsNullOrEmpty(model.DriverId))
                        {
                            string appellationGoodsOwner = string.Empty;
                            if (!string.IsNullOrEmpty(user.Sex))
                            {
                                appellationGoodsOwner = StringExt.AppellationName(user.RealName, user.Sex.Trim());
                            }
                            else
                            {
                                appellationGoodsOwner = user.RealName;
                            }

                            string title = Resource.GoodsOwner + appellationGoodsOwner + Resource.ConfirmTransaction;
                            string body  = model.BookingDate + " " + model.StartAddress + Resource.GoToward + model.TargetAddress;

                            PushMessageViewModel pushMsg = RunPushApi(title, body, user.Id, model.DriverId, 3, result.MessageId.ToString());
                            await RunPushApiAsync(pushMsg);
                        }
                        #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));
        }
示例#2
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));
        }