public ActionResult Create(Sale sale) { var model = db.Create(sale); if (model) { TempData["Success"] = "Thêm giảm giá thành công"; return(RedirectToAction("Index", "Sale")); } else { setViewBag(); TempData["Error"] = "Sửa giá thất bại"; return(View("Create")); } }
private void BtnSave_Click(object sender, RoutedEventArgs e) { if (IsValid() == false) { return; } if (dpStartDate.SelectedDate > dpEndDate.SelectedDate || dpStartDate.SelectedDate < DateTime.Now.AddDays(-1)) { MessageBox.Show("Please pick a valid date.", "Bad date", MessageBoxButton.OK, MessageBoxImage.Information); return; } switch (operation) { case Operation.ADD: sale.StartDate = (DateTime)dpStartDate.SelectedDate; sale.EndDate = (DateTime)dpEndDate.SelectedDate; SaleDAO.Create(sale); break; case Operation.EDIT: foreach (var s in Project.Instance.SalesList) { if (s.ID == sale.ID) { if (s.StartDate != (DateTime)dpStartDate.SelectedDate) { MessageBox.Show("You cannot edit start date.", "Error", MessageBoxButton.OK, MessageBoxImage.Information); return; } s.Discount = sale.Discount; s.StartDate = (DateTime)dpStartDate.SelectedDate; s.EndDate = (DateTime)dpEndDate.SelectedDate; s.Deleted = sale.Deleted; MainWindow.CheckSaleDate(); SaleDAO.Update(s); break; } } break; } this.Close(); }