private void btnSave_Click(object sender, EventArgs e) { try { if (PassedValidation()) { var model = new Course() { DepartmentId = int.Parse(drpdownDept.SelectedValue.ToString()), CourseTitle = txtCourseTitle.Text.ToTitleCase(), CourseCode = txtCourseCode.Text.ToUpper() }; string response; if (lblId.Text == string.Empty) //add { response = _courseRepo.AddCourse(model); if (response == string.Empty) { MessageBox.Show(this, "Course added successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); this.Hide(); } else { MessageBox.Show(this, response, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else //update { model.Id = int.Parse(lblId.Text); response = _courseRepo.UpdateCourse(model); if (response == string.Empty) { MessageBox.Show(this, "Course updated successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); this.Hide(); } else { MessageBox.Show(this, response, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddOrUpdate(Course item) { var saveItem = _id == "" ? _repo.AddCourse(item) : _repo.UpdateCourse(item); if (saveItem == string.Empty) { Base.ShowSuccess("Success", "Course saved successfully"); this.Close(); } else { Base.ShowError("Failed", saveItem); } }
public ActionResult AddCourse(CourseModel model, FormCollection form) { try { CourseRepo CouRepo = new CourseRepo(); if (CouRepo.AddCourse(model, form)) { ViewBag.Message = "Course details added successfully"; } return(RedirectToAction("Addcourse", model)); } catch { ViewBag.Message = "Course details Addition Failed"; return(View()); } }
public Course AddCourse(string id, string fullname, string room) { return(repo.AddCourse(id, fullname, room)); }