private void btmSearchVarata_Click(object sender, EventArgs e) // New order { // Check date again, if user change data, and no do search if (!OrderUtils.CheckCottageBookDate(Convert.ToInt32(dgSearchTable.CurrentRow.Cells[0].Value), dtpSearchFROM.Text, dtpSearchTO.Text)) { btnSearchHae_Click(sender, e); return; } ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand("SELECT toimintaalue_id FROM toimintaalue WHERE nimi Like '" + dgSearchTable.CurrentRow.Cells[1].Value.ToString() + "'", ConnectionUtils.connection); int toimintaalueid = Convert.ToInt32(command.ExecuteScalar().ToString()); // Make object to send on Booking window Cottage cottage = new Cottage(Convert.ToInt32(dgSearchTable.CurrentRow.Cells[0].Value), toimintaalueid, dgSearchTable.CurrentRow.Cells[2].Value.ToString(), dgSearchTable.CurrentRow.Cells[3].Value.ToString(), dgSearchTable.CurrentRow.Cells[4].Value.ToString(), dgSearchTable.CurrentRow.Cells[5].Value.ToString(), Convert.ToInt32(dgSearchTable.CurrentRow.Cells[6].Value.ToString()), dgSearchTable.CurrentRow.Cells[7].Value.ToString(), Convert.ToDouble(dgSearchTable.CurrentRow.Cells[8].Value.ToString())); ConnectionUtils.CloseConnection(); NewBook newbook = new NewBook(cottage, dtpSearchFROM.Value.Date, dtpSearchTO.Value.Date); Booking booking = new Booking(newbook); booking.ShowDialog(); }
public ActionResult Create(string str, string returnUrl) { List <MenuItem> menuItems = db.MenuItems.ToList(); decimal cost = 0; string orderlist = ""; foreach (MenuItem menuItem in menuItems) { int count = int.Parse(Request["input-" + menuItem.ID]); while (count > 0) { if (cost > 0) { orderlist += ","; } cost += menuItem.Price; orderlist += menuItem.ID; count--; } } int order_id = OrderUtils.SaveOrder(User.Identity.Name, orderlist); return(RedirectToAction("Confirm", "Order", new { id = order_id })); }
public virtual ActionResult Confirm(OrderConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetConfirmModel(model.ProductId); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return View(model); } var createdOrder = orderUtils.CreateOrder(model.ProductId); if (createdOrder.OrderStatus == OrderStatus.AwaitingPayment) return RedirectToAction(MVC.Products.Pay.Index(createdOrder.Id)); else if (createdOrder.OrderStatus != OrderStatus.Completed) throw new InvalidOperationException( string.Format("Order status of {0} is not supported", createdOrder.OrderStatus.ToString())); // Order was completed as it was free orderUtils.ActivateOrderedLicenses(createdOrder); string LicenseType = orderUtils.GetLicenseDescription(createdOrder.FillPerfectLicenses.First().LicenseType); return RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)_context.Users.Find(createdOrder.OrderedForId).FillPerfectKey, createdOrder.FillPerfectLicenses.First().EffectiveDate, createdOrder.FillPerfectLicenses.First().ExpirationDate, LicenseType)); }
public void CombineWithPreviousLyric(Lyric lyric) { var previousLyric = Lyrics.GetPrevious(lyric); if (previousLyric == null) { throw new ArgumentNullException(nameof(previousLyric)); } changeHandler?.BeginChange(); // Shifting order that order is larger than current lyric. var lyricOrder = previousLyric.Order; OrderUtils.ShiftingOrder(Lyrics.Where(x => x.Order > lyricOrder).ToArray(), -1); var newLyric = LyricsUtils.CombineLyric(previousLyric, lyric); newLyric.Order = lyricOrder; // Add created lyric and remove old two. beatmap.Add(newLyric); beatmap.Remove(previousLyric); beatmap.Remove(lyric); changeHandler?.EndChange(); }
public void CreateLyric(int?nextToOrder = null) { var maxOrder = OrderUtils.GetMaxOrderNumber(Lyrics.ToArray()); var order = nextToOrder ?? maxOrder; if (order < 0 && order > maxOrder + 1) { throw new ArgumentOutOfRangeException(nameof(order)); } changeHandler?.BeginChange(); // Shifting order that order is larger than current lyric. OrderUtils.ShiftingOrder(Lyrics.Where(x => x.Order > order).ToArray(), 1); // Add new lyric to target order. var createLyric = new Lyric { Text = "New lyric", Order = order + 1, }; beatmap.Add(createLyric); changeHandler?.EndChange(); }
public virtual ActionResult ProcessPayPal(string token, string payerId) { var order = _context.Orders .Where(x => x.PayPalToken == token && x.OrderedForId == CurrentUserId) .FirstOrDefault(); if (order == null || order.OrderStatus != DomainModel.Enums.OrderStatus.AwaitingPayment) { return(RedirectToAction(MVC.Home.Index())); } // Perform the payment string transactionId = ProcessPaypalTransaction(token, payerId, order.TotalPrice); order.PayPalTransactionId = transactionId; order.OrderStatus = OrderStatus.Completed; _context.SaveChanges(); var utils = new OrderUtils(_context, CurrentUserId); utils.ActivateOrderedLicenses(order); string license = utils.GetLicenseDescription(order.FillPerfectLicenses.First().LicenseType); return(RedirectToAction(MVC.Products.FillPerfect.LicenseActivated( (Guid)_context.Users.Find(order.OrderedForId).FillPerfectKey, order.FillPerfectLicenses.First().EffectiveDate, order.FillPerfectLicenses.First().ExpirationDate, license))); }
public void TestChangeOrder(int[] orders, int oldOrder, int nowOrder, int[] movingOrders, int[] newOrder) { try { var objects = orders?.Select(x => new TestOrderObject { Order = x }).ToArray(); // record order index change step. var movingStepResult = new List <int>(); // This utils only change order property. OrderUtils.ChangeOrder(objects, oldOrder, nowOrder, (_, o, _) => { movingStepResult.Add(o); }); // change order result. var result = objects?.Select(x => x.Order).ToArray(); Assert.AreEqual(result, newOrder); // should check moving order step also. Assert.AreEqual(movingStepResult.ToArray(), movingOrders); } catch { Assert.IsNull(newOrder); } }
public IActionResult Get(JObject data) { Order newOrder = JsonConvert.DeserializeObject <Order>(data.ToString()); string orderId = newOrder.orderId; return(OrderUtils.UpdateOrder(newOrder, (order) => order.orderId == newOrder.orderId) ? (ActionResult) new OkObjectResult($"Updated order with order ID: {orderId}") : new BadRequestObjectResult("No result found, nothing to update")); }
public IActionResult Get(JObject data) { Order order = JsonConvert.DeserializeObject <Order>(data.ToString()); order.orderId = Guid.NewGuid().ToString(); return(OrderUtils.WriteOrder(order) ? (ActionResult) new OkObjectResult("Order Added") : new BadRequestObjectResult("Error when adding new order")); }
public void TestGetMaxOrderNumber(int[] orders, int number) { var objects = orders.Select(x => new TestOrderObject { Order = x }).ToArray(); var result = OrderUtils.GetMaxOrderNumber(objects); Assert.AreEqual(result, number); }
public void TestContainDuplicatedId(int[] orders, bool containDuplicated) { var objects = orders.Select(x => new TestOrderObject { Order = x }).ToArray(); var result = OrderUtils.ContainDuplicatedId(objects); Assert.AreEqual(result, containDuplicated); }
public virtual ActionResult ConfirmFillPerfectOrgOrder() { var orderUtils = new OrderUtils(_context, CurrentUserId); var model = orderUtils.GetFpOrgConfirmModel(); if (model == null) throw new InvalidOperationException("Organization does not have a FP license"); return View(model); }
public void ChangeLyricOrder(Lyric lyric, int newIndex) { var oldOrder = lyric.Order; var newOrder = newIndex + 1; // order is start from 1 OrderUtils.ChangeOrder(Lyrics.ToArray(), oldOrder, newOrder, (switchSinger, oldOrder, newOrder) => { // todo : not really sure should call update? }); }
public void DeleteLyric(Lyric lyric) { changeHandler?.BeginChange(); // Shifting order that order is larger than current lyric. OrderUtils.ShiftingOrder(Lyrics.Where(x => x.Order > lyric.Order).ToArray(), -1); beatmap.Remove(lyric); changeHandler?.EndChange(); }
public void GetOrder_Morning_OneOfEach_EntreeSideDrink_Test() { string[] inputOrder = new string[] { "morning", "2", "1", "3" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("eggs,toast,coffee", result); }
public void TestSorted(int[] orders, int[] actualOrders) { var objects = orders?.Select(x => new TestOrderObject { Order = x }); var orderedArray = OrderUtils.Sorted(objects); var result = orderedArray?.Select(x => x.Order).ToArray(); Assert.AreEqual(result, actualOrders); }
public void GetOrder_Morning_MultpleOrdersOfEntree_Test() { string[] inputOrder = new string[] { "morning", "1", "1", "3" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("eggs,error", result); }
public void GetOrder_Night_ErrorForMultipleOrdersOfEntree_Test() { string[] inputOrder = new string[] { "night", "1", "1", "2", "3", "5" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("steak,error", result); }
public void GetOrder_Night_InvalidOrder_Test() { string[] inputOrder = new string[] { "night", "1", "2", "3", "5" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("steak,potato,wine,error", result); }
public void GetOrder_Night_MultipleOrdersOfPotato_Test() { string[] inputOrder = new string[] { "night", "1", "2", "2", "4" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("steak,potato(x2),cake", result); }
public void GetOrder_Night_OneOfEach_EntreeSideDrinkDessert_Test() { string[] inputOrder = new string[] { "night", "1", "2", "3", "4" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("steak,potato,wine,cake", result); }
public void GetOrder_Morning_MultipleOrderOfDrink_Test() { string[] inputOrder = new string[] { "morning", "1", "2", "3", "3", "3" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("eggs,toast,coffee(x3)", result); }
public void GetOrder_Morning_GetErrorForDessertOrder_Test() { string[] inputOrder = new string[] { "morning", "1", "2", "3", "4" }; OrderUtils agent = new OrderUtils(); string result = agent.GetOrderOutput(inputOrder); Assert.AreEqual("eggs,toast,coffee,error", result); }
public async Task <List <CBookEntity> > SearchAsync(string searchPath, string searchAuthor, string searchKeyword, IEnumerable <SortableItem> sortables) { var query = this.dbContext.Set <CBookEntity>() .Where <CBookEntity>(book => StringUtils.IsBlank(searchPath) || book.Path.Contains(searchPath)) .Where <CBookEntity>(book => StringUtils.IsBlank(searchAuthor) || book.Author.Contains(searchAuthor)) .Where <CBookEntity>(book => StringUtils.IsBlank(searchKeyword) || book.Title.Contains(searchKeyword) || book.Name.Contains(searchKeyword)); query = OrderUtils.Sort <CBookEntity>(query, sortables); return(await query.ToListAsync <CBookEntity>()); }
public IActionResult Get(JObject data) { Customer customer = JsonConvert.DeserializeObject <Customer>(data.ToString()); List <Order> queryResult = OrderUtils.QueryOrder((order) => { return(CustomerUtils.CompareCustomer(order.customer, customer)); }); return(queryResult.Count >= 1 ? (ActionResult) new OkObjectResult(JsonConvert.SerializeObject(queryResult, Formatting.Indented)) : new BadRequestObjectResult("No result found")); }
public virtual ActionResult ConfirmFillPerfectOrgOrder() { var orderUtils = new OrderUtils(_context, CurrentUserId); var model = orderUtils.GetFpOrgConfirmModel(); if (model == null) { throw new InvalidOperationException("Organization does not have a FP license"); } return(View(model)); }
public async Task <List <AVideoEntity> > SearchAsync(string searchPath, string searchProducer, string searchKeyword, IEnumerable <SortableItem> sortables) { //var Id = new SqlParameter("author", "%" + searchAuthor + "%"); var query = this.dbContext.Set <AVideoEntity>() .Where <AVideoEntity>(video => StringUtils.IsBlank(searchPath) || video.Path.Contains(searchPath)) .Where <AVideoEntity>(video => StringUtils.IsBlank(searchProducer) || video.Producer.Contains(searchProducer)) .Where <AVideoEntity>(video => StringUtils.IsBlank(searchKeyword) || video.Title.Contains(searchKeyword) || video.Name.Contains(searchKeyword)); query = OrderUtils.Sort <AVideoEntity>(query, sortables); return(await query.ToListAsync <AVideoEntity>()); }
[TestCase(new[] { 4, 3, 2, 1 }, 1, new[] { 5, 4, 3, 2 })] // Not care order in objects and just doing shifting job. public void TestShiftingOrder(int[] orders, int shifting, int[] newOrder) { var objects = orders?.Select(x => new TestOrderObject { Order = x }).ToArray(); OrderUtils.ShiftingOrder(objects, shifting); // convert order result. var result = objects?.Select(x => x.Order).ToArray(); Assert.AreEqual(result, newOrder); }
// GET: MenuOrders/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MenuOrder menuOrder = db.MenuOrders.Find(id); if (menuOrder == null) { return(HttpNotFound()); } return(View(OrderUtils.GetOrderModel(menuOrder))); }
public virtual ActionResult Confirm(int productId) { var orderUtils = new OrderUtils(_context, CurrentUserId); var model = orderUtils.GetConfirmModel(productId); if (model == null) throw new InvalidOperationException( string.Format("Product id {0} was not found", productId)); // Set the effective date to today if the last license expired prior to today if (model.LicenseEffectiveDate <= DateTime.Today) model.LicenseEffectiveDate = DateTime.Today; return View(model); }
public virtual ActionResult Index(int orderId) { var order = _context.Orders .Where(x => x.Id == orderId && x.OrderedForId == CurrentUserId) .FirstOrDefault(); if (order == null || order.OrderStatus != DomainModel.Enums.OrderStatus.AwaitingPayment) { return(RedirectToAction(MVC.Home.Index())); } var model = new OrderUtils(_context, CurrentUserId).GetConfirmModel(order.OrderedProducts.First().ProductId); model.OrderId = orderId; return(View(model)); }
public override bool AddPizza() { var newPizza = OrderUtils.ChosePizza(); if (newPizza != null) { Console.WriteLine("Pizza was added to the order"); order.Pizzas.Add(newPizza); return(true); } else { return(false); } }
public virtual ActionResult ConfirmFillPerfectOrgOrder(FillPerfectOrgLicenseConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetFpOrgConfirmModel(); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return(View(model)); } // Regenerate the model for license details model = orderUtils.GetFpOrgConfirmModel(); // Create the order and automatically activate the license var order = orderUtils.CreateOrder(); order.FillPerfectLicenses.Add(new FpUserLicense { LicenseType = FillPerfectLicenseType.OrganizationGranted, EffectiveDate = model.ActivatedLicenseExpiratioDate >= model.EffectiveLicenseDate ? model.ActivatedLicenseExpiratioDate : model.EffectiveLicenseDate, ExpirationDate = model.ExpirationDate }); // Make sure the user has a FP key var user = _context.Users.Find(order.OrderedForId); if (user.FillPerfectKey == null) { user.FillPerfectKey = Guid.NewGuid(); } _context.SaveChanges(); // Show the user confirmation string orgName = _context.Users.Where(x => x.Id == CurrentUserId).Select(x => x.Organization.Name).FirstOrDefault(); return(RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)user.FillPerfectKey, order.FillPerfectLicenses.First().EffectiveDate, order.FillPerfectLicenses.First().ExpirationDate, "License granted by " + orgName))); }
public virtual ActionResult ConfirmFillPerfectOrgOrder(FillPerfectOrgLicenseConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetFpOrgConfirmModel(); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return View(model); } // Regenerate the model for license details model = orderUtils.GetFpOrgConfirmModel(); // Create the order and automatically activate the license var order = orderUtils.CreateOrder(); order.FillPerfectLicenses.Add(new FpUserLicense { LicenseType = FillPerfectLicenseType.OrganizationGranted, EffectiveDate = model.ActivatedLicenseExpiratioDate >= model.EffectiveLicenseDate ? model.ActivatedLicenseExpiratioDate : model.EffectiveLicenseDate, ExpirationDate = model.ExpirationDate }); // Make sure the user has a FP key var user = _context.Users.Find(order.OrderedForId); if (user.FillPerfectKey == null) user.FillPerfectKey = Guid.NewGuid(); _context.SaveChanges(); // Show the user confirmation string orgName = _context.Users.Where(x => x.Id == CurrentUserId).Select(x => x.Organization.Name).FirstOrDefault(); return RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)user.FillPerfectKey, order.FillPerfectLicenses.First().EffectiveDate, order.FillPerfectLicenses.First().ExpirationDate, "License granted by " + orgName)); }