/// <summary> /// 修改報價 /// </summary> /// <param name="Model"></param> /// <returns></returns> public async Task <JsonResult> ModifyQuote(DriverQuotePriceViewModel Model) { _logger.Information($"ModifyQuote : { JsonConvert.SerializeObject(Model)}"); ResponseViewModel responseResult = new ResponseViewModel(); try { var user = _aspNetUsersService.GetUserModelByName(User.Identity.Name); responseResult = await _bookingService.UpdateOrDeleteQuotedRecordsByCreater(Model, user.Id, "Update"); 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)); }
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)); }
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)); }