public async Task <LecturerNotification> Handle(LecturerCreateCommand request, CancellationToken cancellationToken) { string fullName = request.lecturer.FirstName + " " + request.lecturer.LastName; try { await _repository.Add(request.lecturer); var result = new LecturerNotification() { lecturer = request.lecturer, message = $"Lecturer {fullName} was created successful." }; await _mediator.Publish(result); return(await Task.FromResult(result)); } catch (Exception ex) { await _mediator.Publish(new ErrorNotification { ErrorDescription = ex.Message, ErrorTrace = ex.StackTrace }); var result = new LecturerNotification() { lecturer = request.lecturer, message = $"Some thing is wrong cannot create the lecturer {fullName}." }; return(await Task.FromResult(result)); } }
public async Task <IActionResult> CreateLecturer([FromBody] SaveLecturerResource lecturerResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var lecturer = mapper.Map <SaveLecturerResource, Lecturer>(lecturerResource); var nameExist = await repository.LecturerNameExist(lecturer); if (nameExist != null) { return(Conflict("Lecturer name already exists")); } repository.Add(lecturer); await unitOfWork.CompleteAsync(); lecturer = await repository.GetLecturer(lecturer.Id); var result = mapper.Map <Lecturer, LecturerResource>(lecturer); return(Ok(result)); }
public Lecturer CreateLecture(Lecturer Lecture) { if (!_lectureRepository.Records.Any(x => x.Name == Lecture.Name)) { return(_lectureRepository.Add(Lecture)); } else { return(null); } }
public Lecturer CreateLecturer(Lecturer lecturer) { if (!_lecturerRepository.Records.Any(x => x.Email == lecturer.Email)) { return(_lecturerRepository.Add(lecturer)); } else { return(null); } }
public LecturerCreatedDto CreateLecturer(Lecturer lecturer) { if (_lecturerRepository.Records.Any(x => x.Email == lecturer.Email || x.StaffNumber == lecturer.StaffNumber)) { var createdLecturer = Mapper.Map <Lecturer, LecturerCreatedDto>(lecturer); createdLecturer.IsAvailable = false; return(createdLecturer); } else { lecturer = _lecturerRepository.Add(lecturer); var createdLecturer = Mapper.Map <Lecturer, LecturerCreatedDto>(lecturer); createdLecturer.IsAvailable = true; return(createdLecturer); } }
public IHttpActionResult PostLecturer(LecturerDTO LecturerDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Mapper.Initialize(c => c.CreateMap <LecturerDTO, Lecturer>()); Lecturer Lecturer = Mapper.Map <Lecturer>(LecturerDTO); lecturerRepo.Add(Lecturer); lecturerRepo.Save(); return(CreatedAtRoute("DefaultApi", new { id = Lecturer.ID }, Lecturer)); }
public Lecturer CreateLecturer(Lecturer lecturer1) { var lecturer = new Lecturer() { Name = lecturer1.Name, StaffNumber = lecturer1.StaffNumber, Email = lecturer1.Email, Bibliography = lecturer1.Bibliography, }; if (!_lecturerRepository.Records.Any(x => x.Email == lecturer.Email)) { //student.Id = _studentRepository.Records.Count() + 1; _lecturerRepository.Add(lecturer); } else { return(_lecturerRepository.Records.Where(x => x.Email == lecturer.Email).FirstOrDefault()); } return(lecturer); }
public IHttpActionResult PostLecturer(LecturerDTO lecturerDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Lecturer lecturer = Mapper.Map <Lecturer>(lecturerDTO); lecturerRepo.Add(lecturer); try { lecturerRepo.Save(); return(Ok(lecturer)); } catch { return(BadRequest("Failed to add Lecturer")); } //return CreatedAtRoute("DefaultApi", new { id = Lecturer.ID }, Lecturer); //return Ok(lecturer); }
public Lecturer Create(Lecturer lecturer) { _lecturerRepository.Add(lecturer); return(lecturer); }
public Lecturer Create(Lecturer record) { record = _lectureRepository.Add(record); return(record); }