public IHttpActionResult PostCourse(PocoCourse course) { if (course.InstructorsId != null || course.StudentsId != null) { Course newCourse = new Course() { code = course.Code, name = course.Name, hours = course.Hours, isDeleted = false, }; Course x = db.Course.Add(newCourse); db.SaveChanges(); ctx.Add(x, course); return(CreatedAtRoute("DefaultApi", new { id = x.id }, newCourse)); } else { Course newCourse = new Course() { code = course.Code, name = course.Name, hours = course.Hours, isDeleted = false, }; Course x = db.Course.Add(newCourse); db.SaveChanges(); ctx.Add(x, course); return(CreatedAtRoute("DefaultApi", new { id = x.id }, newCourse)); } }
public void getAllTest() { List <Course> lista = CourseManager.getAll(); int numero = lista.Count; Course c = new Course(); c.CourseID = 5000; c.Title = "berna"; c.Credits = 4; c.DepartmentID = 7; int id = CourseManager.Add(c); lista = CourseManager.getAll(); int numero2 = lista.Count; Assert.AreEqual(numero + 1, numero2); bool elimina = CourseManager.Remove(id); lista = CourseManager.getAll(); int numero3 = lista.Count; Assert.AreEqual(numero, numero3); }
private async void AddBtn_Clicked(object sender, RoutedEventArgs e) { if (course.name != null && course.name != "") { var courselist = await CourseManager.GetCourseList(); if (course.id != null) // update course { await CourseManager.UpdateCourse(course as Models.CourseModel); Frame.GoBack(); } else // add course { course.generateId(); course.updateLessonsByPeroid(); await CourseManager.Add(course as Models.CourseModel); Frame.GoBack(); } } else { Tools.ShowMsgAtFrame("请填写课程名称"); } var nav = WindowWrapper.Current().NavigationServices.FirstOrDefault(); nav.Navigate(typeof(MainPage), null); }
public ActionResult Entry(CourseCreateVm entity) { if (ModelState.IsValid) { var course = Mapper.Map <Course>(entity); var courses = _courseManager.GetAllCourse(); if (courses.FirstOrDefault(x => x.Code == course.Code) != null) { ViewBag.Message = "Exist"; entity.OrganizationSelectListItems = GetAllOrganizationSlItems(); return(View(entity)); } else { bool isAdded = _courseManager.Add(course); if (isAdded) { ViewBag.Message = "Saved"; return(RedirectToAction("Edit", course)); } } } ModelState.AddModelError("", "An Unknown Error Occured!"); entity.OrganizationSelectListItems = GetAllOrganizationSlItems(); //entity.TagsSelectListItems = GetAllTagsSlItems(); return(View(entity)); }
public IActionResult Create([Bind("Id,CourseName,CourseYear")] CourseViewModel courseViewModel) { if (ModelState.IsValid) { Course course = MapToCourse(courseViewModel); _courseManager.Add(course); return(RedirectToAction(nameof(Index), new { message = "create" })); } return(View(courseViewModel)); }
public IActionResult Add(CourseModel model) { if (ModelState.IsValid) { CourseManager.Add(model.Course); return(RedirectToAction("Index")); } return(View(model)); }
protected void btnADDCurso_Click(object sender, EventArgs e) { Course curso = new Course(); curso.CourseID = Convert.ToInt32(this.txtID.Text); curso.Credits = Convert.ToInt32(this.txtCreditos.Text); curso.Title = this.txtNombre.Text; curso.DepartmentID = Convert.ToInt32(this.txtDepartamento.Text); CourseManager.Add(curso); Response.Redirect("cursos.aspx"); }
public void AddTest() { Course c = new Course(); c.CourseID = 345; c.Title = "Titulo"; c.Credits = 1; c.DepartmentID = 1; bool resultado = CourseManager.Add(c); Assert.IsTrue(resultado); CourseManager.Remove(345); }
public void AddCourse_Test() { _manager.Add(COURSE); IList <Course> courses = _manager.GetAll().ToList(); Assert.Equal(1, courses.Count); Course course = courses.First(); Assert.Equal("ASP .NET", course.CourseName); }
public void RemoveTest() { Course c = new Course(); c.CourseID = 5000; c.Title = "berna"; c.Credits = 4; c.DepartmentID = 7; int id = CourseManager.Add(c); bool elimina = CourseManager.Remove(id); Assert.AreEqual(elimina, true); }
public IActionResult Add([FromBody] DTOCourse dtoCourse) { try { _logger.LogInformation("Request Courses/Add"); return(Ok(courseManager.Add(dtoCourse))); } catch (Exception ex) { _logger.LogError("Error during Courses/Add", ex.Message); courseManager.Dispose(); return(StatusCode(500, ex.Message)); } }
public ActionResult Entry(CourseEntryVM model) { if (ModelState.IsValid) { var course = Mapper.Map <Course>(model); bool isAdded = _courseManager.Add(course); if (isAdded) { return(RedirectToAction("Index")); } } model.OrganizationLookUps = _lookUp.GetOrganizations(); return(View(model)); }
public void GetAllTest() { int elementos = CourseManager.GetAll().Count; Course c = new Course(); c.CourseID = 345; c.Title = "Titulo"; c.Credits = 1; c.DepartmentID = 1; CourseManager.Add(c); int elementos2 = CourseManager.GetAll().Count; Assert.AreEqual(elementos + 1, elementos2); CourseManager.Remove(345); }
public void addRemoveTest() { CourseManager course = new CourseManager(); course.CourseID = 666; course.Credits = 45; course.DepartmentID = 2; course.Title = "Test"; int idCursoInsertado = course.Add(course); bool delete = course.Remove(666); Assert.AreEqual(idCursoInsertado, 666); Assert.AreEqual(delete, true); }
public ActionResult CourseEntry(CourseEntryVm model) { if (ModelState.IsValid) { var course = Mapper.Map <Course>(model); bool isAdded = _courseManager.Add(course); if (isAdded) { return(RedirectToAction("CourseInformation", new { course.Id })); } } return(View()); }
protected void btnAdd_Click(object sender, EventArgs e) { if (Convert.ToInt32(this.DropDownList1.SelectedValue) == -1) { return; } Course c = new Course(); c.CourseID = Convert.ToInt32(this.txtID.Text); c.Title = this.txtTitle.Text; c.Credits = Convert.ToInt32(this.txtCredits.Text); c.DepartmentID = Convert.ToInt32(this.DropDownList1.SelectedValue); CourseManager.Add(c); Response.Redirect("Course.aspx"); }
public ActionResult Create(Course course) { if (ModelState.IsValid) { bool IsSaved = _manager.Add(course); if (IsSaved) { ViewBag.Message = "Saved Successfully"; } else { ViewBag.Message = "Saved Failed"; } } ViewBag.DepartmentId = new SelectList(departmentManager.GetAll(), "Id", "Name"); return(View()); }
public IHttpActionResult PostCourse(POCOCourse pocoCourse) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Course course = new Course() { name = pocoCourse.Name, code = pocoCourse.Code, noOfHours = pocoCourse.NoOfHours, }; var c = db.Courses.Add(course); db.SaveChanges(); courseManager.Add(c, pocoCourse); return(CreatedAtRoute("DefaultApi", new { id = c.id }, c)); }
/// <summary> /// Creates the course. /// </summary> /// <param name="unitViewModel">The course view model.</param> public void CreateCourse(CourseViewModel courseViewModel) { try { if (courseViewModel != null) { courseViewModel.Accreditation_Id = courseViewModel.Accreditation_Id == 0 ? (int)AccreditationType.NotSpecified : courseViewModel.Accreditation_Id; courseViewModel.CompanyId = courseViewModel.CompanyId == 0 ? (int)CompanyEnum.Trust : courseViewModel.CompanyId; courseViewModel.CourseTemplate_Id = courseViewModel.CourseTemplate_Id == 0 ? (int)CourseTemplateEnum.DefaultTemplate : courseViewModel.CourseTemplate_Id; Course course = ObjectMapper.Map <CourseViewModel, Model.Entities.Course>(courseViewModel); course = CourseManager.Add(course); } } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing); } }
public string AddCourse(CourseCreateVM vm) { var course = Mapper.Map <Course>(vm); if (ModelState.IsValid) { bool isAdded = _courseManager.Add(course); if (isAdded) { return("Successfully Saved"); } else { return("Did not saved."); } } return("Sorry! Error Occured."); }
private static void CourseAdd() { try { ICourseService service = new CourseManager(new EfCourseDal()); int id; string name, comment; Console.Write("Please to ıd="); id = Convert.ToInt16(Console.ReadLine()); Console.Write("Please to Name="); name = Console.ReadLine(); Console.WriteLine("Please to Comment="); comment = Console.ReadLine(); service.Add(new Course { Id = id, CourseName = name, Comment = comment }); Console.WriteLine("Succes"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
protected void CourseSaveButton_Click(object sender, EventArgs e) { Courses _Course = new Courses(); _Course.CourseCode = txtCourseCode.Text; decimal countcode = _CourseManager.AlreadyExitCode(_Course); if (countcode >= 1) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('This Code Already Exist');", true); } else { _Course.CourseName = txtCourseName.Text; _Course.CourseCredit = Convert.ToDecimal(txtCredit.Text); _Course.CourseDescription = txtDescription.Text; _Course.DepartmentId = Convert.ToInt32(DepartmentDropDownList.SelectedValue); _Course.SemesterId = Convert.ToInt32(SemestersDropDownList.SelectedValue); decimal countname = _CourseManager.AlreadyExitName(_Course); if (countname >= 1) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('This Name Already Exist');", true); } else { int success = _CourseManager.Add(_Course); if (success > 0) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Succssefully Save Course');", true); } else { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed Saved Course');", true); } } } }
public ActionResult Add(Course course) { _courseManager.Add(course); return(View()); }