public async Task <HttpResponseMessage> AddDelivery( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "Deliveries")] HttpRequest req) { string token = req.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (_authorizationsService.IsTokenValid(token, true)) { // Get Delivery from JSON object StreamReader r = new StreamReader(req.Body); string requestBody = await r.ReadToEndAsync(); r.Dispose(); // Dispose StreamReader so it cannot be used anymore dynamic data = JsonConvert.DeserializeObject <dynamic>(requestBody); Delivery filledDelivery = await _locationsService.SetLocationFromAddress(data); // Add Delivery Delivery d = await _deliveriesService.AddDelivery(filledDelivery); // Creating new notification bool result = await _notificationsService.CreateNotification(d.Id, d.Vehicle, d.DueDate, new LatLng(d.Warehouse.Latitude, d.Warehouse.Longitude), new LatLng(d.Customer.Latitude, d.Customer.Longitude)); if (!result) { return(new HttpResponseMessage(HttpStatusCode.FailedDependency)); } dynamic config = JsonConvert.DeserializeObject(File.ReadAllText("../../../variables.json")); int expirationInSeconds = ((int)config["NotificationsService"]["ExpirationOfNotificationInMinutes"] * 60); // Create task in scheduler to check for an expired Notification record Scheduler.Scheduler.Instance().ScheduleJob("CheckNotificationContextForExpiration", "trigger_CheckNotificationContextForExpiration", DateTime.Now, (expirationInSeconds + 60), 0); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(d), Encoding.UTF8, "application/json") }); } // Authorized access only return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); }
public IActionResult AddDelivery(Delivery delivery) { if (!_permissionService.Authorize("AddDelivery")) { return(Error("无操作权限!")); } delivery.Code = delivery.Code.Trim(); delivery.Name = delivery.Name.Trim(); var result = _deliveriesService.ConfirmDeliveryIsExist(delivery.Code); delivery.ShopCode = delivery.ShopCode?.Trim(); if (result == null) { _deliveriesService.AddDelivery(delivery); //更新快递方式信息到WMS _scheduleTaskFuncService.OmsSyncDeliverys(); return(Success()); } else { return(Error("已有相同编码的物流方式")); } }