public ActionResult AddCourse(Course cor) { if (ModelState.IsValid) { corRepo.Create(cor); return(RedirectToAction("Index", "Home")); } return(View(cor)); }
public ActionResult GotoTr(Trainer train) { if (ModelState.IsValid) { trainRepo.Create(train); TempData["Trainer"] = train; return(RedirectToAction("Index", "Home")); } return(View(train)); }
public ActionResult GotoStu(Student stud) { if (ModelState.IsValid) { studentRepo.Create(stud); //ViewBag return(RedirectToAction("Index", "Home")); } return(View(stud)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { productRepo.Create(product); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create(Course data) { if (ModelState.IsValid) { data = corRepository.Create(data); return(RedirectToAction("Index")); } return(View(data)); }
public ActionResult Create(Module mod) { if (ModelState.IsValid) { modRepo.Create(mod); return(RedirectToAction("Index")); } return(View(mod)); }
public ActionResult Create(StudentInfo data) { if (ModelState.IsValid) { data = catRepository.Create(data); return(RedirectToAction("Index")); } return(View(data)); }
public ActionResult Create(Trainer data) { if (ModelState.IsValid) { data = traRepository.Create(data); return(RedirectToAction("Index")); } return(View(data)); }
/// <summary> /// http://localhost:<PORT>/api/CategoryAPI /// </summary> /// <returns></returns> public IHttpActionResult Post(Category data) { if (ModelState.IsValid) { var result = catRepository.Create(data); return(Ok(data)); } // if the Model is invalid the return vaidation error messages return(BadRequest(ModelState)); }
public ActionResult Create(Category data) { // Validate the posted model with ModelState property of the Controller base class // This validations will be executed based on Validation rules applied on // Model classes using Data Annotations if (ModelState.IsValid) { // then only save the data data = catRepo.Create(data); // Redirect to the Index Action Method return(RedirectToAction("Index")); } // if the model is invalid stay on the same veiw and display // Validation errors return(View(data)); }
public ActionResult Create(Product data) { // read the CategoryRowId entered for Product Category cat = new Category(); cat.CategoryRowId = data.CategoryRowId; // retrived the BAsePrice of the Category Based on CategoryRowId int basePrice = catRepository.GetData(cat.CategoryRowId).BasePrice; if (data.Price < basePrice) { ViewBag.PriceError = $"Base Price for Category is {basePrice} that is " + $"greated that price" + $" you entered. Please enter value greater than equalto the Price."; ViewBag.CategoryRowId = new SelectList(catRepository.GetData(), "CategoryRowId", "SubCategoryName"); return(View(data)); } // Validate the posted model with ModelState property of the Controller base class // This validations will be executed based on Validation rules applied on // Model classes using Data Annotations if (ModelState.IsValid) { if (data.Price < 0) { throw new Exception("Price Can not be -Ve"); } // then only save the data data = prdRespository.Create(data); // Redirect to the Index Action Method return(RedirectToAction("Index")); } // if the model is invalid stay on the same veiw and display // Validation errors // Make sure that pass the ViewBag / ViewData agian to view // otherwise the veiw will crash because the CateryRowId on Creaye View // is useing DroDownList to show list og Categories // List out all Categories and pass it to SelectList object of System.Web.Mvc // ViewBag.CategoryRowId, the CategoryRowId key is selected because, it is present into // Product class. So when the View is submitted, the CategoryRowId value will also be // submitted with Product class. // Collection to be passed, Value that will be selected, value taht will be shown on UI ViewBag.CategoryRowId = new SelectList(catRepository.GetData(), "CategoryRowId", "SubCategoryName"); return(View(data)); }
public ActionResult register(StudentCourse data) { Student s = new Student(); s.StudentRowId = data.StudentRowId; Course c = new Course(); c.CourseRowId = data.CourseRowId; if (ModelState.IsValid) { data = StudentCourseRepository.Create(data); ViewBag.StudentRowId = new SelectList(StudentRepository.GetData(), "StudentRowId", "StudentId"); ViewBag.CourseKeyId = new SelectList(CourseRepository.GetData(), "CourseRowId", "CourseName"); return(RedirectToAction("Index")); } return(View(data)); }
public ActionResult Create(Category data) { try { // Validate the posted model with ModelState property of the Controller base class // This validations will be executed based on Validation rules applied on // Model classes using Data Annotations if (ModelState.IsValid) { // if BasePrice is -Ve then throw exception if (data.BasePrice < 0) { // store data in TempData TempData["Category"] = data; throw new Exception("Price Cannot be -ve"); } // then only save the data data = catRepository.Create(data); // Redirect to the Index Action Method return(RedirectToAction("Index")); } // if the model is invalid stay on the same veiw and display // Validation errors return(View(data)); } catch (Exception ex) { // handle the exception and return to Error.cshtml // this is a standard error view in Views/Shared folder // this view has a Model class as HandleErrorInfo from System.Web.Mvc return(View("Error", new HandleErrorInfo( ex, // controller name RouteData.Values["controller"].ToString(), // action name RouteData.Values["action"].ToString() ))); } }