public async Task <ActionResult <LecturerModel> > GetById(int id) { if (id <= 0) { ModelState.AddModelError(nameof(id), "'id' must be positive."); return(BadRequest(ModelState)); } try { LecturerDto?dto = await _service.GetLecturer(id); if (dto == null) { return(NotFound()); } var model = _mapper.Map <LecturerModel>(dto); return(model); } catch (IncorrectIdException e) { _logger.LogWarning(e, "It seems, validation does not cover some errors."); return(BadRequest(e.Message)); } }
public async Task <ActionResult <LecturerDto> > GetLecturer(int id) { try { var result = await _lecturerService.GetLecturer(id); if (result == null) { return(NotFound()); } return(result); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorRetrievingDataFromDataBase)); } }
public ActionResult AboutLecturer(string id) { if (string.IsNullOrEmpty(id)) { throw new ValidationException("id doesn't exist", ""); } LecturerDTO lecturerDto = lecturerService.GetLecturer(Convert.ToInt32(id)); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <LecturerDTO, LecturerViewModel>()).CreateMapper(); var lecturer = mapper.Map <LecturerDTO, LecturerViewModel>(lecturerDto); return(View(lecturer)); }
public ActionResult CreateCour(CreateCourse createCourse, HttpPostedFileBase uploadImage) { createCourse.lecturers = lecturerService.GetLecturers().ToList(); if (uploadImage == null) { ModelState.AddModelError("ImageName", "Add image"); } if (ModelState.IsValid) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } createCourse.Image = imageData; var lec = lecturerService.GetLecturer(createCourse.SelectedLecId); Lecturer res = new Lecturer { LecturerId = lec.LecturerId, Courses = lec.Courses, Department = lec.Department, FirstName = lec.FirstName, SecondName = lec.SecondName, Image = lec.Image, ImageName = lec.ImageName, Information = lec.Information, LecturerEmail = lec.LecturerEmail }; try { courseService.AddCourse(new CourseDTO { CourseName = createCourse.CourseName, Description = createCourse.Description, CourseStart = createCourse.CourseStart, CourseEnd = createCourse.CourseEnd, ForTerm = createCourse.ForTerm, Image = createCourse.Image, ImageName = createCourse.CourseName, IsDeleted = createCourse.IsDeleted, Lecturer = res }, createCourse.SelectedLecId, createCourse.Topics); } catch (ValidationException ex) { ModelState.AddModelError("CourseStart", ex.Message); } if (ModelState.IsValid) { return(Redirect("/Manage/Index")); } else { createCourse.lecturers = lecturerService.GetLecturers().ToList(); return(View(createCourse)); } } return(View(createCourse)); }
public LecturerContract GetLecturer(int id) { return(_lecturerService.GetLecturer(id).ToDataContract()); }
private void dataGrid_Selection(object sender, EventArgs e) { if (executedFirstTime) { executedFirstTime = false; return; } try { int selectedIndex = dataGridLecturers.SelectedRows[0].Index; if (selectedIndex != -1) { if (dataGridLecturers.SelectedRows[0].Cells[0].Value != null) { int id = int.Parse(dataGridLecturers.SelectedRows[0].Cells[0].Value.ToString()); selectedLec = lecturerService.GetLecturer(id); #region Set data to Fields textBoxLecturerName.Text = selectedLec.Name; textBoxEmployeeID.Text = selectedLec.EmployeeID; switch (selectedLec.Faculty) { case "Computing": comboBoxFaculty.SelectedIndex = 0; break; case "Engineering": comboBoxFaculty.SelectedIndex = 1; break; case "Business": comboBoxFaculty.SelectedIndex = 2; break; case "Humanities & Sciences": comboBoxFaculty.SelectedIndex = 3; break; } textBoxDepartment.Text = selectedLec.Department; switch (selectedLec.Center) { case "Malabe": comboBoxCenter.SelectedIndex = 0; break; case "Metro": comboBoxCenter.SelectedIndex = 1; break; case "Matara": comboBoxCenter.SelectedIndex = 2; break; case "Kandy": comboBoxCenter.SelectedIndex = 3; break; case "Kurunagala": comboBoxCenter.SelectedIndex = 4; break; case "Jaffna": comboBoxCenter.SelectedIndex = 5; break; } switch (selectedLec.Building) { case "New building": comboBoxBuilding.SelectedIndex = 0; break; case "A-block": comboBoxBuilding.SelectedIndex = 1; break; case "B-block": comboBoxBuilding.SelectedIndex = 2; break; case "C-block": comboBoxBuilding.SelectedIndex = 3; break; case "D-block": comboBoxBuilding.SelectedIndex = 4; break; case "E-block": comboBoxBuilding.SelectedIndex = 5; break; } switch (selectedLec.Level) { case 1: comboBoxLevel.SelectedIndex = 0; break; case 2: comboBoxLevel.SelectedIndex = 1; break; case 3: comboBoxLevel.SelectedIndex = 2; break; case 4: comboBoxLevel.SelectedIndex = 3; break; case 5: comboBoxLevel.SelectedIndex = 4; break; case 6: comboBoxLevel.SelectedIndex = 5; break; case 7: comboBoxLevel.SelectedIndex = 6; break; } textBoxRank.Text = selectedLec.Rank; #endregion btnUpdate.Enabled = true; btnDelete.Enabled = true; } } }catch (ArgumentOutOfRangeException es) { Console.WriteLine(es.Message); } }