public ActionResult <Order> GetOrder() { try { var orderIdFromToken = HttpContext.User.FindFirst("orderId").Value; Order order = _database.GetOrderById(orderIdFromToken); return(order); } catch (ArgumentNullException) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Request must contain an email." })); } catch (Exception err) { Console.WriteLine(err); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Internal server error." })); } }
public IActionResult SaveImagesToOrder([FromBody] Image image) { try { IActionResult response; if (image == null) { return(response = BadRequest(new { message = "No images was found in request body" })); } Order order = DB.GetOrderById(image.orderId); image.installationId = order.installationId; image.estateId = order.estateId; image.externalImageReference = Guid.NewGuid().ToString(); image.deliveryPackageId = "tilldelas vid sändning till next"; image.extension = Image.ExtensionType.JPG; image.imageQuality = Image.ImageQualityType.print; image.submittedToNext = image.submittedToNext; this.DB.AddImagesToOrder(image); response = StatusCode(StatusCodes.Status201Created, new { message = image.externalImageReference }); return(response); } catch (Exception err) { Console.WriteLine(err.ToString()); IActionResult response = StatusCode(StatusCodes.Status500InternalServerError, err.ToString()); return(response); } }
public async Task <IActionResult> DeliverOrder([FromBody] UpdatedOrder order) { try { HttpContext.Request.Headers.TryGetValue("Authorization", out var token); var currentPhotographerEmail = HttpContext.User; Order orderInDb = _database.GetOrderById(order.orderId); if (!OrderBelongsToPhotographer(currentPhotographerEmail, orderInDb.photographerEmail)) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Requested order does not belong to the provided photographer." })); } if (orderInDb.status == StatusType.Delivered) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "The order is already delivered." })); } if (order.status != StatusType.Delivered) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "A photographer can only change the status of an order to delivered." })); } _database.UpdateOrderStatus(order.orderId, order.status); string deliverMsg = $"Order {order.status} by {order.photographerEmail}."; bool orderstatusChangedOnHub = await ChangeOrderstatusOnHub(order, deliverMsg, token, _config); if (orderstatusChangedOnHub) { return(StatusCode(StatusCodes.Status200OK, new { message = deliverMsg })); } else { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Hub request did not succeed." })); } } catch (ArgumentNullException) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Put request must contain an orderId." })); } catch (OrderDoesNotExistException) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "The provided orderId does not exist." })); } catch (Exception err) { Console.WriteLine(err); return(StatusCode(500)); } }