private void Insert_Click(object sender, RoutedEventArgs e) { OrderEditView.IsEnabled = true; OrderEditView.Visibility = Visibility.Visible; OrderEditView.Initialize(); EditHeight.Height = new GridLength(120); }
public static Order UpdateOrderFromOrderEditView(OrderEditView view) { ApplicationDbContext db = new ApplicationDbContext(); Order orderDetails = UpdateOrderFromOrderEditView(db, view); db.Dispose(); return(orderDetails); }
public static OrderEditView GetOrderEditView(Guid orderId, IPrincipal user) { ApplicationDbContext db = new ApplicationDbContext(); OrderEditView view = GetOrderEditView(db, orderId, user); db.Dispose(); return(view); }
private void Update_Click(object sender, RoutedEventArgs e) { if (OrderTable.SelectedIndex >= 0) { OrderCase Item = (dynamic)OrderTable.SelectedItem; OrderEditView.IsEnabled = true; OrderEditView.Visibility = Visibility.Visible; OrderEditView.Initialize(Item); EditHeight.Height = new GridLength(120); } }
public async Task <ActionResult> Edit(OrderEditView order, List <OrderPositionEditView> positions) { order.Positions = positions; if (ModelState.IsValid) { var dbOrder = await _repository.Order.Find(order.OrderId); dbOrder.CustomerId = order.CustomerId; dbOrder.OrderDate = order.OrderDate; dbOrder.Discount = order.Discount; foreach (var position in positions) { var found = false; foreach (var dbPosition in dbOrder.Positions) { if (position.Position == dbPosition.Position) { dbPosition.ProductId = position.ProductId; dbPosition.Amount = position.Amount; dbPosition.Price = position.Price; dbPosition.Discount = position.Discount; found = true; break; } } if (!found) { dbOrder.Positions.Add(new OrderPosition { Position = position.Position, ProductId = position.ProductId, Amount = position.Amount, Price = position.Price, Discount = position.Discount, }); } } await _repository.Commit(); return(RedirectToAction("Details", new { id = order.OrderId })); } ViewBag.CustomerId = new SelectList(await _repository.Customer.GetAll(), "CustomerId", "FName", order.CustomerId); return(View(order)); }
public static Order UpdateOrderFromOrderEditView(ApplicationDbContext db, OrderEditView view) { Order orderDetails = GetOrder(db, view.OrderId); orderDetails.OrderQuanity = view.OrderQuanity; orderDetails.OrderStatus = view.OrderStatus; orderDetails.OrderCreationDateTime = view.OrderCreationDateTime; orderDetails.OrderDistributionDateTime = view.OrderDistributionDateTime; orderDetails.OrderDeliveredDateTime = view.OrderDeliveredDateTime; orderDetails.OrderCollectedDateTime = view.OrderCollectedDateTime; orderDetails.OrderClosedDateTime = view.OrderClosedDateTime; db.Entry(orderDetails).State = EntityState.Modified; db.SaveChanges(); return(orderDetails); }
// GET: Orders/Edit/5 public ActionResult Details(Guid?id, bool showHistory) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrderEditView order = OrderEditHelpers.GetOrderEditView(db, id.Value, User); if (order == null) { return(HttpNotFound()); } ViewBag.ShowHistory = showHistory; return(View(order)); }
public OrderEditView Initialize(ActionBarView actionBar, string databaseName, AuftragsverwaltungViewModel viewModel) { mDatabaseName = databaseName; mEmployeeRepository = new Repository <Employee>(mDatabaseName); mViewModel = viewModel; OrderEditView ret = new OrderEditView(); ret.DataContext = mViewModel; actionBar.DataContext = new ActionBarViewModel { }; ret.InitializeComponent(); return(ret); }
public ActionResult Details(OrderEditView order) { if (ModelState.IsValid) { if (Request.Form["despatchedbutton"] != null) { //Update tables OrderHelpers.ChangeOrderStatus(db, order.OrderId, OrderStatusEnum.Despatched, User); return(RedirectToAction("Orders", "ManageListings")); } if (Request.Form["delivereddbutton"] != null) { //Update tables OrderHelpers.ChangeOrderStatus(db, order.OrderId, OrderStatusEnum.Delivered, User); return(RedirectToAction("Orders", "ManageListings")); } if (Request.Form["collectedbutton"] != null) { //Update tables OrderHelpers.ChangeOrderStatus(db, order.OrderId, OrderStatusEnum.Collected, User); return(RedirectToAction("Orders", "ManageListings")); } if (Request.Form["receivedbutton"] != null) { //Update tables OrderHelpers.ChangeOrderStatus(db, order.OrderId, OrderStatusEnum.Received, User); return(RedirectToAction("Orders", "ManageListings")); } if (Request.Form["closedbutton"] != null) { //Update tables OrderHelpers.ChangeOrderStatus(db, order.OrderId, OrderStatusEnum.Closed, User); return(RedirectToAction("Orders", "ManageListings")); } } order = OrderEditHelpers.GetOrderEditView(db, order.OrderId, User); ViewBag.ShowHistory = false; return(View(order)); }
public static OrderEditView GetOrderEditView(ApplicationDbContext db, Guid orderId, IPrincipal user) { Order orderDetails = OrderHelpers.GetOrder(db, orderId); AppUser orderAppUser = null; Branch orderBranch = null; AppUser offerAppUser = null; Branch offerBranch = null; AppUser listingAppUser = null; Branch listingBranch = null; Offer offerDetails = null; AvailableListing availableListing = null; RequirementListing requirementListing = null; if (orderDetails.OrderOriginatorAppUserId != null) { if (orderDetails.OrderOriginatorAppUserId.Value != Guid.Empty) { orderAppUser = AppUserHelpers.GetAppUser(db, orderDetails.OrderOriginatorAppUserId.Value); } } if (orderDetails.OrderOriginatorBranchId != null) { if (orderDetails.OrderOriginatorBranchId.Value != Guid.Empty) { orderBranch = BranchHelpers.GetBranch(db, orderDetails.ListingOriginatorBranchId.Value); } } if (orderDetails.OfferOriginatorAppUserId != null) { if (orderDetails.OfferOriginatorAppUserId.Value != Guid.Empty) { offerAppUser = AppUserHelpers.GetAppUser(db, orderDetails.OfferOriginatorAppUserId.Value); } } if (orderDetails.OfferOriginatorBranchId != null) { if (orderDetails.OfferOriginatorBranchId.Value != Guid.Empty) { offerBranch = BranchHelpers.GetBranch(db, orderDetails.OfferOriginatorBranchId.Value); } } if (orderDetails.ListingOriginatorAppUserId != null) { if (orderDetails.ListingOriginatorAppUserId.Value != Guid.Empty) { listingAppUser = AppUserHelpers.GetAppUser(db, orderDetails.ListingOriginatorAppUserId.Value); } } if (orderDetails.ListingOriginatorBranchId != null) { if (orderDetails.ListingOriginatorBranchId.Value != Guid.Empty) { listingBranch = BranchHelpers.GetBranch(db, orderDetails.ListingOriginatorBranchId.Value); } } if (orderDetails.OfferId != null) { if (orderDetails.OfferId.Value != Guid.Empty) { offerDetails = OfferHelpers.GetOffer(db, orderDetails.OfferId.Value); if (orderDetails.ListingId != null) { if (orderDetails.ListingId.Value != Guid.Empty) { switch (offerDetails.ListingType) { case ListingTypeEnum.Available: availableListing = AvailableListingHelpers.GetAvailableListing(db, orderDetails.ListingId.Value); break; case ListingTypeEnum.Requirement: requirementListing = RequirementListingHelpers.GetRequirementListing(db, orderDetails.ListingId.Value); break; } } } } } OrderEditView view = new OrderEditView() { OrderId = orderDetails.OrderId, ListingType = orderDetails.ListingType, OrderQuanity = orderDetails.OrderQuanity, OrderStatus = orderDetails.OrderStatus, OrderCreationDateTime = orderDetails.OrderCreationDateTime, OrderDistributionDateTime = orderDetails.OrderDistributionDateTime, OrderDeliveredDateTime = orderDetails.OrderDeliveredDateTime, OrderCollectedDateTime = orderDetails.OrderCollectedDateTime, OrderClosedDateTime = orderDetails.OrderClosedDateTime, OrderAppUser = orderAppUser, OrderBranchDetails = orderBranch, OfferId = orderDetails.OfferId.GetValueOrDefault(), OfferAppUser = offerAppUser, OfferBranchDetails = offerBranch, OfferDetails = offerDetails, ListingId = orderDetails.ListingId.GetValueOrDefault(), ListingAppUser = listingAppUser, ListingBranchDetails = listingBranch, AvailableListingDetails = availableListing, RequirementListingDetails = requirementListing }; AppUser thisAppUser = AppUserHelpers.GetAppUser(db, user); //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level Company thisCompany = CompanyHelpers.GetCompanyForUser(db, user); //set Inhouse flag view.InhouseOrder = OrderProcessHelpers.SetInhouseFlag(orderDetails, thisAppUser, thisCompany); //Set OrderOut flag view.OrderOut = OrderProcessHelpers.SetOrderOutFlag(orderDetails, view.InhouseOrder); //set buttons bool?displayDespatchButton = null; bool?displayDeliveredButton = null; bool?displayReceivedButton = null; bool?displayCollectedButton = null; bool?displayClosedButton = null; OrderProcessHelpers.SetOrderButtons(db, user, orderDetails, view.OrderOut, out displayDespatchButton, out displayDeliveredButton, out displayReceivedButton, out displayCollectedButton, out displayClosedButton); view.DisplayDespatchButton = displayDespatchButton; view.DisplayDeliveredButton = displayDeliveredButton; view.DisplayReceivedButton = displayReceivedButton; view.DisplayCollectedButton = displayCollectedButton; view.DisplayClosedButton = displayClosedButton; return(view); }