public async Task <string> GetEmployeeId([FromBody] UpdatedOrder order) { try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://hubtest.megler.vitec.net/"); // client.BaseAddress = new Uri ("https://hub.megler.vitec.net/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "Vml0ZWNmb3RvcG9ydGFsOmFtSzlzY0VnSnpNd1Bqckdack03bUNIY1llWEdsbmxDdEIyQ3JweHU0YTlIa25Eektn"); string uri = order.installationId + "/Estates/" + order.estateId; dynamic result = await client.GetStringAsync(uri); result = JsonConvert.DeserializeObject <object> (result); Console.WriteLine(result.brokersIdWithRoles[0].employeeId); return(result.brokersIdWithRoles[0].employeeId); } catch (Exception err) { Console.WriteLine(err); return(null); } }
/// <summary> /// Updates any order line items when a shipment is deleted to null /// </summary> /// <param name="shipment"> /// The shipment. /// </param> private void UpdateOrderLineItemShipmentKeys(IShipment shipment) { using (var repository = _repositoryFactory.CreateOrderRepository(_uowProvider.GetUnitOfWork())) { // there really should only ever be one of these var orderKeys = shipment.Items.Select(x => ((OrderLineItem)x).ContainerKey).Distinct(); foreach (var orderKey in orderKeys) { var order = repository.Get(orderKey); if (order != null) { var items = order.Items.Where(x => ((OrderLineItem)x).ShipmentKey == shipment.Key); foreach (var item in items) { ((OrderLineItem)item).ShipmentKey = null; } repository.AddOrUpdate(order); UpdatedOrder.RaiseEvent(new SaveEventArgs <IOrder>(order), this); } } } }
public OrderUpdateCommand(UpdatedOrder updatedOrder) { if (updatedOrder == null) { throw new ArgumentNullException(nameof(updatedOrder)); } this.UpdatedOrder = updatedOrder; }
public Order GetLastOrder() { if (UpdatedOrder == null) { return(this); } else { return(UpdatedOrder.GetLastOrder()); } }
public async Task <IActionResult> GetEstateInfo([FromBody] UpdatedOrder order) { try { var result = await BrokerController.GetEstateInfoFromNext(order); var response = Ok(new { result }); return(response); } catch (Exception err) { Console.WriteLine(err); return(null); } }
public async Task <IActionResult> Update([FromBody] UpdatedOrder updatedOrder) { var command = new OrderUpdateCommand(updatedOrder); var result = await this._mediator.Send(command); if (result.Status == CommandResultStatus.Success) { return(new OkResult()); } return(new BadRequestResult()); }
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)); } }
// TODO // Move this function into separate helper function along with all Next calls, // that can be used for both Norwegian and Swedish API // then we don't have to use it as static and pass config as parameter (bad practice) public static async Task <bool> ChangeOrderstatusOnHub(UpdatedOrder order, string msg, string token, IConfiguration _config) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://hubtest.megler.vitec.net/"); // client.BaseAddress = new Uri ("https://hub.megler.vitec.net/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "Vml0ZWNmb3RvcG9ydGFsOmFtSzlzY0VnSnpNd1Bqckdack03bUNIY1llWEdsbmxDdEIyQ3JweHU0YTlIa25Eektn"); string uri = order.installationId + "/Orders/" + order.orderId + "/Status?message=" + msg + "&status=" + order.status + "&url=" + _config["SiteBaseUrl"] + "/maklare"; dynamic response = await client.PostAsync(uri, null); if (response.StatusCode == HttpStatusCode.NoContent) { return(true); } return(false); }
public void PlaceOrder(UpdatedOrder item) { using (var context = new eRaceContext()) { if (item.OrderID == 0) { // adding a new order var order = new Order(); order.TaxGST = item.Tax; order.SubTotal = item.SubTotal; order.VendorID = item.VendorID; order.Comment = item.VendorComment; order.Closed = false; order.OrderDate = DateTime.Now; var list = (from a in context.Orders where a.OrderNumber != null select a.OrderNumber); order.OrderNumber = int.Parse(list.Max().ToString()) + 1; order.EmployeeID = 1; context.Orders.Add(order); foreach (var y in item.UpdatedOrderDetails) { var additem = new OrderDetail { ProductID = y.ProductID, Quantity = y.OrderQty, Cost = y.UnitCost, OrderUnitSize = y.UnitSize }; var product = context.Products.Find(additem.ProductID); product.QuantityOnOrder += additem.Quantity * additem.OrderUnitSize; context.Entry(product).State = System.Data.Entity.EntityState.Modified; order.OrderDetails.Add(additem); } context.SaveChanges(); } else // updating an pending order { var order = context.Orders.Find(item.OrderID); var orderdetails = context.OrderDetails.Where(x => x.OrderID == order.OrderID).ToList(); order.OrderID = item.OrderID; order.TaxGST = item.Tax; order.SubTotal = item.SubTotal; order.VendorID = item.VendorID; order.Comment = item.VendorComment; order.Closed = false; order.OrderDate = DateTime.Now; var list = (from a in context.Orders where a.OrderNumber != null select a.OrderNumber); order.OrderNumber = int.Parse(list.Max().ToString()) + 1; order.EmployeeID = 1; foreach (var a in orderdetails) { var existingitem = item.UpdatedOrderDetails.SingleOrDefault(x => x.ProductID == a.ProductID); if (existingitem == null) { context.Entry(a).State = System.Data.Entity.EntityState.Deleted; } else { a.Cost = existingitem.UnitCost; a.Quantity = existingitem.OrderQty; context.Entry(a).State = System.Data.Entity.EntityState.Modified; var product = context.Products.Find(a.ProductID); product.QuantityOnOrder += existingitem.OrderQty * existingitem.UnitSize; context.Entry(product).State = System.Data.Entity.EntityState.Modified; } } foreach (var y in item.UpdatedOrderDetails) { var newproduct = !orderdetails.Any(x => x.ProductID == y.ProductID); if (newproduct == true) { var additem = new OrderDetail { ProductID = y.ProductID, OrderID = item.OrderID, Quantity = y.OrderQty, Cost = y.UnitCost, OrderUnitSize = y.UnitSize }; order.OrderDetails.Add(additem); var product = context.Products.Find(additem.ProductID); product.QuantityOnOrder += additem.Quantity * additem.OrderUnitSize; context.Entry(product).State = System.Data.Entity.EntityState.Modified; } } context.Entry(order).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } }
public void SaveOrder(UpdatedOrder item, int?EmployeeID) { using (var context = new eRaceContext()) { if (item.OrderID == 0) // adding a new order { var order = new Order(); order.TaxGST = item.Tax; order.SubTotal = item.SubTotal; order.VendorID = item.VendorID; order.Comment = item.VendorComment; order.Closed = false; order.OrderDate = null; order.OrderNumber = null; order.EmployeeID = EmployeeID.Value; context.Orders.Add(order); foreach (var y in item.UpdatedOrderDetails) { var addskill = new OrderDetail { ProductID = y.ProductID, Quantity = y.OrderQty, Cost = y.UnitCost, OrderUnitSize = y.UnitSize }; order.OrderDetails.Add(addskill); } context.SaveChanges(); } else // updating an existing order { var order = context.Orders.Find(item.OrderID); var orderdetails = context.OrderDetails.Where(x => x.OrderID == order.OrderID).ToList(); order.OrderID = item.OrderID; order.TaxGST = item.Tax; order.SubTotal = item.SubTotal; order.VendorID = item.VendorID; order.Comment = item.VendorComment; order.Closed = false; order.OrderDate = null; order.OrderNumber = null; order.EmployeeID = 1; foreach (var a in orderdetails) { var existingitem = item.UpdatedOrderDetails.SingleOrDefault(x => x.ProductID == a.ProductID); if (existingitem == null) { context.Entry(a).State = System.Data.Entity.EntityState.Deleted; } else { a.Cost = existingitem.UnitCost; a.Quantity = existingitem.OrderQty; context.Entry(a).State = System.Data.Entity.EntityState.Modified; } } foreach (var y in item.UpdatedOrderDetails) { var newproduct = !orderdetails.Any(x => x.ProductID == y.ProductID); if (newproduct == true) { var addskill = new OrderDetail { ProductID = y.ProductID, OrderID = item.OrderID, Quantity = y.OrderQty, Cost = y.UnitCost, OrderUnitSize = y.UnitSize }; order.OrderDetails.Add(addskill); } } context.Entry(order).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } }
protected void PlaceOrder_Click(object sender, EventArgs e) { List <Exception> errors = new List <Exception>(); MessageUserControl.TryRun(() => { var controller = new PurchasingController(); int vendorid = int.Parse(VendorDropDown.SelectedValue.ToString()); string comments = VendorComments.Text; string subtotal = Subtotal.Text; string tax = Tax.Text; string total = Total.Text; decimal subtotalcount = 0; List <UpdatedOrderDetail> orderitems = new List <UpdatedOrderDetail>(); if (!(OrderGridview.Rows.Count < 1)) { foreach (GridViewRow row in OrderGridview.Rows) { var item = new UpdatedOrderDetail(); item.ProductID = int.Parse((row.FindControl("ProductID") as HiddenField).Value.ToString()); string a = (row.FindControl("UnitCostLabel") as TextBox).Text.ToString(); string b = (row.FindControl("OrderQtyLabel") as TextBox).Text.ToString(); if (String.IsNullOrEmpty(a) || String.IsNullOrEmpty(b)) { throw new Exception("Please fill up the Order Quantity and Unit Cost textboxes before proceeding"); } item.UnitCost = decimal.Parse(a); item.OrderQty = int.Parse((row.FindControl("OrderQtyLabel") as TextBox).Text.ToString()); item.UnitSize = int.Parse((row.FindControl("UnitSize") as HiddenField).Value.ToString()); decimal itemprice = decimal.Parse((row.FindControl("ItemPriceLabel") as HiddenField).Value.ToString()); decimal extendedprice = decimal.Parse((row.FindControl("ExtendedCostLabel") as Label).Text.ToString()); subtotalcount += (item.UnitCost * item.OrderQty); if (extendedprice != (item.UnitCost * item.OrderQty)) { errors.Add(new Exception("Please press the refresh button to update the extended costs of the product rows")); } else { if (item.UnitCost <= 0) { errors.Add(new Exception("Unit Cost can not be zero or negative value. Please review the product rows with !!")); } if (item.OrderQty <= 0) { errors.Add(new Exception("Order Quantity can not be zero or negative value. Please review the product rows with !!")); } else if (itemprice > (item.UnitCost / item.UnitSize)) { errors.Add(new Exception("Per Item cost is lower than the item's selling price. Please review the product rows with !!")); } } orderitems.Add(item); } if (subtotal == "0") { errors.Add(new Exception("Subtotal can not be zero. Please press the refresh button")); } if (errors.Any()) { throw new BusinessRuleCollectionException("Failure to proceed with the Save request", errors); } else { UpdatedOrder order = new UpdatedOrder(); var orderexists = controller.GetOrder(vendorid); if (orderexists != null) // checking if pending order exists { order.OrderID = orderexists.OrderID; } else { order.OrderID = OrderID; } order.VendorComment = comments; order.SubTotal = decimal.Parse(subtotal.ToString()); order.Tax = decimal.Parse(tax.ToString()); order.Total = decimal.Parse(total.ToString()); order.VendorID = vendorid; order.UpdatedOrderDetails = orderitems; controller.PlaceOrder(order); DeleteOrder.Visible = false; PlaceOrder.Visible = false; SaveOrder.Visible = false; messenger.Text = $"Order successfully placed"; OrderGridview.Enabled = false; VendorRepeater.Visible = false; VendorComments.Enabled = false; } } else { throw new Exception("Please select at least one Product item from the Vendor Catalog"); } }, "Success", "Order successfully placed"); }
public async Task <IActionResult> UpdateOrder([FromBody] UpdatedOrder order) { try { HttpContext.Request.Headers.TryGetValue("Authorization", out var token); var orderId = HttpContext.User.FindFirst("orderId").Value; Order orderInDb = _database.GetOrderById(orderId); if (order == null) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Requested order does not exist." })); } if (orderInDb.status == StatusType.Cancelled) { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Order is already cancelled. You can't edit details of an order after it is cancelled." })); } if (orderInDb.status == StatusType.Created) { if (order.status == StatusType.InProgress) { orderInDb.photographerEmail = order.photographerEmail; orderInDb.description = order.description; orderInDb.status = order.status; _database.UpdateOrder(orderInDb); string updatedMsg = $"Order {order.status} with {order.photographerEmail} assigned as Photographer."; // Calling hub bool orderstatusChangedOnHub = await OrderController.ChangeOrderstatusOnHub(order, updatedMsg, token, _config); if (orderstatusChangedOnHub) { return(StatusCode(StatusCodes.Status200OK, new { message = updatedMsg })); } else { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Hub request did not succeed." })); } } } if (order.status == StatusType.Cancelled) { _database.UpdateOrderStatus(orderId, order.status); string cancelledMsg = "Order 'Cancelled'."; // Calling hub bool orderstatusChangedOnHub = await OrderController.ChangeOrderstatusOnHub(order, cancelledMsg, token, _config); if (orderstatusChangedOnHub) { return(StatusCode(StatusCodes.Status200OK, new { message = cancelledMsg })); } else { return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Hub request did not succeed." })); } } IActionResult badRequest = BadRequest(new { message = "Select a valid status of the order." }); return(badRequest); } 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)); } }
private static async Task <Newtonsoft.Json.Linq.JObject> GetEstateInfoFromNext(UpdatedOrder order) { try { HttpClient client = new HttpClient(); // TODO stringconstants for hub-urls client.BaseAddress = new Uri("https://hubtest.megler.vitec.net/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", AUTHENTICATION_VALUE); string uri = order.installationId + "/Estates/" + order.estateId; dynamic result = await client.GetStringAsync(uri); result = JsonConvert.DeserializeObject <object> (result); return(result); } catch (Exception err) { Console.WriteLine(err); return(null); } }