public async Task <LecturerDto?> UpdateLecturer(LecturerDto lecturerDto) { var result = await appDbContext.Lecturers.FindAsync(lecturerDto.Id); if (result != null) { result.FirstName = lecturerDto.FirstName; result.LastName = lecturerDto.LastName; result.Token = lecturerDto.Token; result.Email = lecturerDto.Email; result.Password = lecturerDto.Password; result.BirthDate = lecturerDto.BirthDate; result.Gender = (Gender)lecturerDto.Gender; result.PhotoPath = lecturerDto.PhotoPath; result.ActiveTill = lecturerDto.ActiveTill; result.IsActive = lecturerDto.IsActive; result.WorkingRate = lecturerDto.WorkingRate; result.Role = (Role)lecturerDto.Role; await appDbContext.SaveChangesAsync(); return(mapper.Map <LecturerDto>(result)); } return(null); }
public async Task <ApplicationResponse <LecturerDto> > GetByIdAsync(string lecturerId) { Guid lecturerGuid = new Guid(); if (Guid.TryParse(lecturerId, out lecturerGuid)) { Lecturer lecturer = await _lecturerRepository.GetByIdAsync(lecturerGuid); var appResp = new ApplicationResponse <LecturerDto>(); if (lecturer != null) { LecturerDto dto = _mapper.Map <LecturerDto>(lecturer); appResp.Response = dto; appResp.Message = "OK"; return(appResp); } else { appResp.AddError("Not Found"); return(appResp); } } else { var response = new ApplicationResponse <LecturerDto>(); response.Response = new LecturerDto(); response.AddError("Identifier is in a wrong format."); return(response); } }
public async Task <int> UpdateLecturer(LecturerDto lecturerDto) { if (lecturerDto.Id <= 0) { throw new IncorrectIdException("Id must be positive number"); } Lecturer lecturer = _mapper.Map <Lecturer>(lecturerDto); try { int id = await _repository.SaveAsync(lecturer); return(id); } catch (EntityNotFoundException e) { _logger.LogWarning(e, "Unable to update lecturer which does not exist"); throw; } catch (DataException e) { _logger.LogError(e, "Unable to save a lecturer"); throw new UnexpectedDataException("Unable to save a lecturer", e); } }
public async Task Create([FromBody] LecturerDto lecturer) { await _commandDispatcher.Dispatch <CreateLecturer.Command>(new CreateLecturer.Command() { lecturer = lecturer }); }
public LecturerDto GetByIdWithDetails(int id) { LecturerDto lecturer = Mapper.Map <Lecturer, LecturerDto>(_lecturerRepository.GetById(id)); var query = from c in _courseRepository.Records join lc in _lecturerCourseRepository.Records on c.Id equals lc.CourseId where lc.LecturerId == id select c; lecturer.Courses = Mapper.Map <List <Course>, List <CourseDto> >(query.ToList()); return(lecturer); }
public async Task <LecturerDto> AddLecturer(LecturerDto lecturerDto) { var lecturer = new Lecturer(); lecturerDto.SetToken(); mapper.Map(lecturerDto, lecturer); var result = await appDbContext.Lecturers.AddAsync(lecturer); await appDbContext.SaveChangesAsync(); return(mapper.Map <LecturerDto>(result.Entity)); }
public ActionResult <LecturerDto> CreateLecturer(LecturerDto lecturerDto) { var lecturerModel = _mapper.Map <Lecturer>(lecturerDto); var rand = new Random(); lecturerModel.EmployeeId = rand.Next(100000, 1000000); //TODO EmployeeId Identity _repository.Create(lecturerModel); _repository.SaveChanges(); var lecturerCreatedDto = _mapper.Map <LecturerDto>(lecturerModel); return(CreatedAtRoute(nameof(GetLecturerById), new { Id = lecturerModel.Id }, lecturerCreatedDto)); }
public ActionResult UpdateLecturer(int id, LecturerDto lecturerDto) { var lecturerModelFromRepo = _repository.GetById(id); if (lecturerModelFromRepo == null) { return(NotFound()); } _mapper.Map(lecturerDto, lecturerModelFromRepo); lecturerModelFromRepo.Id = id; _repository.Update(lecturerModelFromRepo); _repository.SaveChanges(); return(NoContent()); }
protected async Task HandleValidSubmit() { LecturerDto result = null; if (Lecturer.Id != 0) { result = await LecturerService.UpdateLecturer(Lecturer); } else { result = await LecturerService.CreateLecturer(Lecturer); } if (result != null) { NavigationManager.NavigateTo("/lecturers"); } }
public async Task <ActionResult <LecturerDto> > CreateLecturer(LecturerDto lecturer) { try { if (lecturer == null) { return(BadRequest()); } return(await _lecturerService.AddLecturer(lecturer)); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorRetrievingDataFromDataBase)); } }
public IActionResult Add([FromBody] LecturerDto Lecturer) { try { if (lecturerService.Add(Lecturer)) { return(Ok("Successfully Added")); } else { return(BadRequest("Failed To Add")); } } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult UpdateByID(int id, [FromBody] LecturerDto Lecturer) { try { if (lecturerService.Update(id, Lecturer)) { return(Ok("Successfully Updated")); } else { return(BadRequest("Failed to Update")); } } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task AddLecturerTest(LecturerDto lecturerDto, Lecturer expected) { // Arrange Mock <ICrudRepository <Lecturer> > repositoryMock = new(); var loggerMock = new Mock <ILogger <LecturerService> >(); var mapperMock = new Mock <IMapper>(); mapperMock.Setup(mapper => mapper.Map <Lecturer>(lecturerDto)).Returns(expected); var service = new LecturerService(repositoryMock.Object, mapperMock.Object, loggerMock.Object); // Act int id = await service.AddLecturer(lecturerDto); // Assert Assert.That(id, Is.EqualTo(expected.Id)); repositoryMock.Verify(repository => repository.SaveAsync(expected, It.IsAny <CancellationToken>())); repositoryMock.VerifyNoOtherCalls(); }
public async Task <ActionResult <LecturerDto?> > UpdateLecturer(LecturerDto lecturer) { try { var lecturerForUpdate = await _lecturerService.GetLecturer(lecturer.Id); if (lecturerForUpdate == null) { return(NotFound($"Lecturer with id = {lecturer.Id} was not found")); } return(await _lecturerService.UpdateLecturer(lecturer)); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorUpdatingDatabase)); } }
public async Task <int> AddLecturer(LecturerDto lecturerDto) { if (lecturerDto.Id != 0) { throw new IncorrectIdException("Lecturer id must be equal to 0"); } Lecturer lecturer = _mapper.Map <Lecturer>(lecturerDto); try { return(await _repository.SaveAsync(lecturer)); } catch (DataException e) { _logger.LogError(e, "Unable to save a lecturer"); throw new UnexpectedDataException("Unable to save a lecturer", e); } }
public async Task <ApplicationResponse <bool> > CreateAsync(LecturerDto lecturer) { Lecturer domainObj = _mapper.Map <Lecturer>(lecturer); bool created = await _lecturerRepository.CreateAsync(domainObj); lecturer.Id = domainObj.Id; if (created) { return(new ApplicationResponse <bool> { Message = "OK" }); } else { var response = new ApplicationResponse <bool>(); response.AddError("Sorry, Something went wrong"); return(response); } }
public IQueryable <LecturerDto> Search([FromBody] LecturerSearchRequest request) { var lecturer = Db.Members.Where(x => x.Organiser.ShortName.Equals(request.Organiser)).ToList(); var response = new List <LecturerDto>(); foreach (var member in lecturer) { var dto = new LecturerDto { Faculty = member.Organiser.ShortName, FirstName = member.FirstName, LastName = member.Name, ShortName = member.ShortName }; response.Add(dto); } return(response.AsQueryable()); }
protected async override Task OnInitializedAsync() { int.TryParse(Id, out int lecturerId); if (lecturerId != 0) { PageHeaderText = "Edit Lecturer"; Lecturer = await LecturerService.GetLecturer(int.Parse(Id)); } else { PageHeaderText = "Create Lecturer"; Lecturer = new LecturerDto { // LecturerId = 1, // BirthDate = DateTime.Now, PhotoPath = "images/nopic.jpg", ActiveTill = DateTime.Now }; } }
public async Task <IActionResult> Post([FromBody] LecturerDto lecturer) { if (ModelState.IsValid) { var resp = await _lecturerApplication.CreateAsync(lecturer); if (resp.Succeeded) { return(CreatedAtRoute(nameof(GetAsync), new { id = lecturer.Id }, lecturer)); } else { ModelState.AddModelError("Error", resp.Message); return(BadRequest(ModelState)); } } else { return(BadRequest(ModelState)); } }
public async Task <LecturerDto> UpdateLecturer(LecturerDto lecturer) { return(await httpClient.PutJsonAsync <LecturerDto>("api/lecturer", lecturer)); }
public Task CreateLecturer(LecturerDto lecturer) { throw new NotImplementedException(); }
public async Task <IActionResult> Post([FromBody] LecturerDto createLecturerDto) { return(Ok(await _service.CreateLecturer(createLecturerDto))); }
public async Task <LecturerDto> CreateLecturer(LecturerDto newLecturer) { return(await httpClient.PostJsonAsync <LecturerDto>("api/lecturer", newLecturer)); }
/// <summary> /// /// </summary> public CourseSummaryDto ConvertSummary(Course course) { var dto = new CourseSummaryDto(); var courseService = new CourseService(_db); var summary = courseService.GetCourseSummary(course); dto.Id = course.Id; dto.Name = course.Name; dto.ShortName = course.ShortName; dto.Description = course.Description; dto.IsCoterie = course.Occurrence.IsCoterie; dto.HasHomeBias = course.Occurrence.HasHomeBias; foreach (var host in summary.Lecturers) { var lecturer = new LecturerDto(); lecturer.FirstName = host.FirstName; lecturer.LastName = host.Name; lecturer.Title = host.Title; if (!string.IsNullOrEmpty(host.UrlProfile)) { lecturer.AddAction("Profile", host.UrlProfile); } if (dto.Lecturer == null) { dto.Lecturer = new List <LecturerDto>(); } dto.Lecturer.Add(lecturer); } foreach (var room in summary.Rooms) { var courseRoom = new RoomDto(); courseRoom.Number = room.Number; courseRoom.Building = room.Number.Substring(0, 1); if (courseRoom.Number.StartsWith("K") || courseRoom.Number.StartsWith("L")) { courseRoom.Campus = "Pasing"; } else if (courseRoom.Number.StartsWith("F")) { courseRoom.Campus = "Karlstrasse"; } else { courseRoom.Campus = "Lothstrasse"; } if (dto.Locations == null) { dto.Locations = new List <RoomDto>(); } dto.Locations.Add(courseRoom); } foreach (var activityDate in summary.Dates) { var courseDate = new AppointmentDto(); courseDate.DayOfWeekName = activityDate.DayOfWeek.ToString(); courseDate.TimeBegin = activityDate.StartTime.ToString(); courseDate.TimeEnd = activityDate.EndTime.ToString(); if (dto.Appointments == null) { dto.Appointments = new List <AppointmentDto>(); } dto.Appointments.Add(courseDate); } foreach (var nexus in course.Nexus) { var module = new ModuleDto(); var curr = new CurriculumDto(); curr.Name = nexus.Requirement.Option.Package.Curriculum.Name; curr.ShortName = nexus.Requirement.Option.Package.Curriculum.ShortName; curr.Organiser = new OrganiserDto(); curr.Organiser.Name = nexus.Requirement.Option.Package.Curriculum.Organiser.Name; curr.Organiser.ShortName = nexus.Requirement.Option.Package.Curriculum.Organiser.ShortName; curr.Organiser.Color = nexus.Requirement.Option.Package.Curriculum.Organiser.HtmlColor; module.Id = nexus.Requirement.Id; module.Curriculum = curr; module.Ects = nexus.Requirement.ECTS; module.UsCredits = nexus.Requirement.USCredits; module.Sws = nexus.Requirement.SWS; if (dto.Modules == null) { dto.Modules = new List <ModuleDto>(); } dto.Modules.Add(module); } return(dto); }
internal CourseDateDto ConvertDate(ActivityDate activityDate) { var courseDate = new CourseDateDto { Id = activityDate.Id, From = activityDate.Begin, Until = activityDate.End, Begin = activityDate.Begin.ToUniversalTime().ToString(@"yyyyMMdd\THHmmss\Z"), End = activityDate.End.ToUniversalTime().ToString(@"yyyyMMdd\THHmmss\Z"), IsCanceled = activityDate.Occurrence.IsCanceled, Title = activityDate.Title }; foreach (var host in activityDate.Hosts) { var lecturer = new LecturerDto { FirstName = host.FirstName, LastName = host.Name, Title = host.Title }; if (!string.IsNullOrEmpty(host.UrlProfile)) { lecturer.AddAction("Profile", host.UrlProfile); } if (courseDate.Lecturer == null) { courseDate.Lecturer = new List <LecturerDto>(); } courseDate.Lecturer.Add(lecturer); } foreach (var room in activityDate.Rooms) { var courseRoom = new RoomDto { Number = room.Number, Building = room.Number.Substring(0, 1) }; if (courseRoom.Number.StartsWith("K") || courseRoom.Number.StartsWith("L")) { courseRoom.Campus = "Pasing"; } else if (courseRoom.Number.StartsWith("F")) { courseRoom.Campus = "Karlstrasse"; } else { courseRoom.Campus = "Lothstrasse"; } if (courseDate.Rooms == null) { courseDate.Rooms = new List <RoomDto>(); } courseDate.Rooms.Add(courseRoom); } return(courseDate); }