public IActionResult CreateEmployee(Guid companyId, [FromBody] EmployeeForCreationDto employee) { var company = _repository.Company.GetCompany(companyId, false); if (company == null) { _logger.LogInfo($"Company with id {companyId} doesn't exits"); return(NotFound()); } if (employee == null) { _logger.LogError("EmployeeForCreationDto object sent from the client is null"); return(BadRequest("EmployeeForCreationDto object is null")); } var employeeEntity = _mapper.Map <Employee>(employee); _repository.Employee.CreateEmployee(companyId, employeeEntity); _repository.Save(); var employeeToReturn = _mapper.Map <EmployeeDto>(employeeEntity); return(CreatedAtRoute("GetEmployeeForCompany", new { companyId, id = employeeToReturn.Id }, employeeToReturn)); }
public IActionResult CreateEmployeeForCompany(Guid companyId, [FromBody] EmployeeForCreationDto employee) { if (employee == null) { _logger.LogError("EmployeeForCreationDto object sent from client is null."); return(BadRequest("EmployeeForCreationDto object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid model state for the EmployeeForCreationDto object"); return(UnprocessableEntity(ModelState)); } var company = _repository.Company.GetCompany(companyId, trackChanges: false); if (company == null) { _logger.LogInfo($"Company with id: {companyId} doesn't exist in the database."); return(NotFound()); } var employeeEntity = _mapper.Map <Employee>(employee); _repository.Employee.CreateEmployeeForCompany(companyId, employeeEntity); _repository.Save(); var employeeToReturn = _mapper.Map <EmployeeDto>(employeeEntity); return(CreatedAtRoute("GetEmployeeForCompany", new { companyId, id = employeeToReturn.Id }, employeeToReturn)); }
public IActionResult CreateAssignmentForCourse(Guid courseId, [FromBody] AssignmentForCreationDto assignment) { if (assignment == null) { _logger.LogError("AssignmentForCreationDto object sent from client is null."); return(BadRequest("AssignmentForCreationDto object is null")); } var course = _repository.Course.GetCourse(courseId, trackChanges: false); if (course == null) { _logger.LogInfo($"Course with id: {courseId} doesn't exist in the database."); return(NotFound()); } var assignmentEntity = _mapper.Map <Assignment>(assignment); _repository.Assignment.CreateAssignmentForCourse(courseId, assignmentEntity); _repository.Save(); var assignmentToReturn = _mapper.Map <AssignmentDto>(assignmentEntity); return(CreatedAtRoute("GetAssignmentForCourse", new { courseId, id = assignmentToReturn.Id }, assignmentToReturn)); }
public IActionResult UpdateUser(Guid id, [FromBody] UserForUpdateDto user) { if (user == null) { _logger.LogError("UserForUpdateDto object sent from client is null."); return(BadRequest("UserForUpdateDto object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid model state for the UserForUpdateDto object"); return(UnprocessableEntity(ModelState)); } var userEntity = _repository.User.GetUser(id, trackChanges: true); if (userEntity == null) { _logger.LogInfo($"User with id: {id} doesn't exist in the database."); return(NotFound()); } _mapper.Map(user, userEntity); _repository.Save(); return(NoContent()); }
public IActionResult CreateAssinmentForEnrollment(Guid enrollmentId, [FromBody] AssignmentForCreationDto assignment) { if (assignment == null) { _logger.LogError("AssignmentForCreationDto object sent from client is null."); return(BadRequest("AssignmentForCreationDto object is null")); } // var organization = _repository.Company.GetCompany(companyId, trackChanges: false); var enrollment = _repository.Enrollment.GetEnrollments(enrollmentId, trackChanges: false); if (enrollment == null) { _logger.LogInfo($"Section with id: {enrollmentId} doesn't exist in the database."); return(NotFound()); } var assignmentEntity = _mapper.Map <Assignment>(assignment); // _repository.Employee.CreateEmployeeForCompany(companyId, employeeEntity); _repository.Assignment.CreateAssignmentForEnrollment(enrollmentId, assignmentEntity); _repository.Save(); var assignmentToReturn = _mapper.Map <AssignmentDto>(assignmentEntity); return(CreatedAtRoute(new { enrollmentId, id = assignmentToReturn.Id }, assignmentToReturn)); }
public IActionResult AddFriends(string num1, string num2) { _repository.Friends.AddFriend(num1, num2); _repository.Save(); return(Ok(NoContent())); }
public IActionResult CreateUserForOrganization(Guid orgId, [FromBody] UserForCreationDto user) { if (user == null) { _logger.LogError("UserForCreationDto object sent from client is null."); return(BadRequest("UserForCreationDto object is null")); } // var organization = _repository.Company.GetCompany(companyId, trackChanges: false); var organization = _repository.Organization.GetOrganization(orgId, trackChanges: false); if (organization == null) { _logger.LogInfo($"Organization with id: {orgId} doesn't exist in the database."); return(NotFound()); } var userEntity = _mapper.Map <User>(user); // _repository.Employee.CreateEmployeeForCompany(companyId, employeeEntity); _repository.User.CreateUserForOrganization(orgId, userEntity); _repository.Save(); var userToReturn = _mapper.Map <UserDto>(userEntity); return(CreatedAtRoute("GetUserForOrganization", new { orgId, id = userToReturn.Id }, userToReturn)); // return CreatedAtRoute( new { orgId, id = userToReturn.Id }, userToReturn); }
public IActionResult CreateSectionForCourse(Guid courseId, [FromBody] SectionForCreationDto section) { if (section == null) { _logger.LogError("SectionForCreationDto object sent from client is null."); return(BadRequest("SectionForCreationDto object is null")); } // var organization = _repository.Company.GetCompany(companyId, trackChanges: false); var course = _repository.Course.GetCourses(courseId, trackChanges: false); if (course == null) { _logger.LogInfo($"User with id: {courseId} doesn't exist in the database."); return(NotFound()); } var sectionEntity = _mapper.Map <Section>(section); // _repository.Employee.CreateEmployeeForCompany(companyId, employeeEntity); _repository.Section.CreateSectionForCourse(courseId, sectionEntity); _repository.Save(); var sectionToReturn = _mapper.Map <SectionDto>(sectionEntity); return(CreatedAtRoute(new { courseId, id = sectionToReturn.Id }, sectionToReturn)); }
public IActionResult CreateEnrollmentForCourse(Guid userId, [FromBody] EnrollmentForCreationViaUserDto enrollment) { if (enrollment == null) { _logger.LogError("EnrollmentForCreationDto object sent from client is null."); return(BadRequest("EnrollmentForCreationDto object is null")); } var user = _repository.User.GetUser(userId, trackChanges: false); if (user == null) { _logger.LogInfo($"User with id: {userId} doesn't exist in the database."); return(NotFound()); } var enrollmentEntity = _mapper.Map <Enrollment>(enrollment); _repository.Enrollment.CreateEnrollmentForUser(userId, enrollmentEntity); _repository.Save(); var enrollmentToReturn = _mapper.Map <EnrollmentDto>(enrollmentEntity); return(CreatedAtRoute("GetEnrollmentForUser", new { userId, id = enrollmentToReturn.Id }, enrollmentToReturn)); }
public IActionResult CreateSubmissionForAssinment(Guid assignmentId, [FromBody] SubmissionForCreationDto submission) { if (submission == null) { _logger.LogError("SubmissionForCreationDto object sent from client is null."); return(BadRequest("SubmissionForCreationDto object is null")); } // var organization = _repository.Company.GetCompany(companyId, trackChanges: false); var assignment = _repository.Assignment.GetAssignments(assignmentId, trackChanges: false); if (assignment == null) { _logger.LogInfo($"Section with id: {assignmentId} doesn't exist in the database."); return(NotFound()); } var submissionEntity = _mapper.Map <Submission>(submission); // _repository.Employee.CreateEmployeeForCompany(companyId, employeeEntity); _repository.Submission.CreateSubmissionForAssignment(assignmentId, submissionEntity); _repository.Save(); var submissionToReturn = _mapper.Map <SubmissionDto>(submissionEntity); return(CreatedAtRoute(new { assignmentId, id = submissionToReturn.Id }, submissionToReturn)); }
public IActionResult CreateSubmissionForEnrollment(Guid userId, Guid enrollmentId, [FromBody] SubmissionForCreationDto submission) { var user = _repository.User.GetUser(userId, trackChanges: false); if (user == null) { _logger.LogInfo($"User with id: {userId} doesn't exist in the database."); return(NotFound()); } var enrollment = _repository.Enrollment.GetOneEnrollmentForUser(userId, enrollmentId, trackChanges: false); if (enrollment == null) { _logger.LogInfo($"User with id: {enrollmentId} doesn't exist in the database."); return(NotFound()); } var submissionEntity = _mapper.Map <Submission>(submission); _repository.Submission.CreateSubmissionForEnrollment(enrollmentId, submissionEntity); _repository.Save(); var submissionToReturn = _mapper.Map <SubmissionDto>(submissionEntity); return(CreatedAtRoute("GetSubmissionForEnrollment", new { userId, enrollmentId, id = submissionToReturn.Id }, submissionToReturn)); }
public async Task <IActionResult> CreateTicket(TicketForCreationDto ticket) { if (ticket == null) { _logger.LogError("Ticket object sent from client is null."); return(BadRequest("Empty Ticket Cannot Be Created")); } if (!ModelState.IsValid) { _logger.LogError("Invalid model state for the Ticket"); return(UnprocessableEntity(ModelState)); } ticket.TStatusId = new Guid("4bb96000-7e4c-4e69-ae20-08d934dbcd3a"); var ticketToCreate = _mapper.Map <Ticket>(ticket); var userList = User.Claims.ToList(); //Getting the username and email from jwt token to set it to CreatedBy name and email var userName = User.Claims.ToList()[1].Value; var userEmail = User.Claims.ToList()[3].Value; ticketToCreate.SubmittedByName = userName; ticketToCreate.SubmittedByEmail = userEmail; ticketToCreate.CreatedAt = DateTime.Now; _repo.Ticket.CreateTicket(ticketToCreate); await _repo.Save(); return(Ok("Ticket Created Sucessfully")); }
public IActionResult CreateCourseForUser(Guid userId, [FromBody] CourseForCreationDto course) { if (course == null) { _logger.LogError("CourseForCreationDto object sent from client is null."); return(BadRequest("CourseForCreationDto object is null")); } // var organization = _repository.Company.GetCompany(companyId, trackChanges: false); var user = _repository.User.GetUsers(userId, trackChanges: false); if (user == null) { _logger.LogInfo($"User with id: {userId} doesn't exist in the database."); return(NotFound()); } var courseEntity = _mapper.Map <Course>(course); // _repository.Employee.CreateEmployeeForCompany(companyId, employeeEntity); _repository.Course.CreateCourseForUser(userId, courseEntity); _repository.Save(); var courseToReturn = _mapper.Map <CourseDto>(courseEntity); return(CreatedAtRoute(new { userId, id = courseToReturn.Id }, courseToReturn)); }
private void SubmitAction() { if (entryType == EntryType.NewEntry) { Person personToSave = new Person() { FirstName = PersonFirstName, LastName = PersonLastName, Addresses = Addresses }; if (PersonId.HasValue) { personToSave.Id = PersonId.Value; } _repository.Person.CreatePerson(personToSave); _repository.Save(); } else { UpdatePersonRecord(); SubmitAddresses(); } closeView(); }
public async Task <IActionResult> SetPhoto(int id) { Event eventModel = _repository.Events.GetById(id, true); if (eventModel == null) { return(NotFound()); } string oldFile = Path.Combine(_appEnvironment.ContentRootPath, _appEnvironment.WebRootPath, "images/" + eventModel.Photo); if (System.IO.File.Exists(oldFile)) { System.IO.File.Delete(oldFile); } var file = Request.Form.Files[0]; string fName = eventModel.Name + "_" + Guid.NewGuid() + Path.GetExtension(file.FileName); eventModel.Photo = fName; string path = Path.Combine(_appEnvironment.ContentRootPath, _appEnvironment.WebRootPath, "images/" + fName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } _repository.Save(); return(NoContent()); }
public async Task <IActionResult> AddSection([FromBody] Subsection subsection) { await _repository.Subsection.Create(subsection); await _repository.Save(); return(CreatedAtRoute(nameof(GetSubsectionById), subsection.Id, subsection)); }
public ActionResult <CompanyDto> CreateCompany([FromBody] CompanyForCreationDto companyForCreationDto) { var company = mapper.Map <Company>(companyForCreationDto); company.Id = Guid.NewGuid(); repository.Company.CreateCompany(company); repository.Save(); return(CreatedAtRoute(nameof(GetCompany), new { id = company.Id }, mapper.Map <CompanyDto>(company))); }
public async Task <PokemonDto> PostPokemonAsync(PokemonForCreationDto pokemonForCreationDto) { var pokemonEntity = _mapper.Map <Pokemon>(pokemonForCreationDto); _repositoryManager.Pokemon.CreatePokemon(pokemonEntity); await _repositoryManager.Save(); return(_mapper.Map <PokemonDto>(pokemonEntity)); }
public IActionResult Post([FromBody] Donation donation) { _repository.Donation.CreateDonation(donation); _repository.Save(); return(CreatedAtAction("GetDonations", new { id = donation.Id }, new { Donation = donation })); }
public IActionResult Post([FromBody] UserDonation userDonation) { _repository.UserDonation.CreateUserDonation(userDonation); _repository.Save(); return(CreatedAtAction("GetById", new { id = userDonation.Id }, new { UserDonation = userDonation })); }
public IActionResult Post([FromBody] Gender gender) { _repository.Gender.CreateGender(gender); _repository.Save(); return(CreatedAtAction("GetById", new { id = gender.Id }, new { Gender = gender })); }
public IActionResult Insert(Company model) { if (ModelState.IsValid) { _repositoryManager.Company.CreateCompany(model); _repositoryManager.Save(); ViewBag.Message = "Bedrijf toegevoegd"; } return(View(model)); }
public IActionResult Post([FromBody] UserType type) { _repository.Type.CreateType(type); _repository.Save(); return(CreatedAtAction("GetById", new { id = type.Id }, new { Type = type })); }
public IActionResult CreateOrganization([FromBody] OrganizationForCreationDto organization) { var organizationEntity = _mapper.Map <Organization>(organization); _repository.Organization.CreateOrganization(organizationEntity); _repository.Save(); var organizationToReturn = _mapper.Map <OrganizationDto>(organizationEntity); return(CreatedAtRoute("getOrganizationById", new { id = organizationToReturn.Id }, organizationToReturn)); }
public override IActionResult Create([FromBody] CreateItem item) { var assignmentEntity = _mapper.Map <Assignment>(item); _repository.Assignment.CreateAssignment(assignmentEntity); _repository.Save(); var assignmentToReturn = _mapper.Map <AssignmentDto>(assignmentEntity); return(CreatedAtRoute("getAssignmentById", new { id = assignmentToReturn.Id }, assignmentToReturn)); }
public CompanyDto CreateCompany(CompanyForCreationDto company) { var companyEntity = _mapper.Map <Company>(company); _companyRepository.CreateCompany(companyEntity); _repositoryManager.Save(); var companyToReturn = _mapper.Map <CompanyDto>(companyEntity); return(companyToReturn); }
public IActionResult Post([FromBody] DonationStatus status) { _repository.Status.CreateStatus(status); _repository.Save(); return(CreatedAtAction("GetById", new { id = status.Id }, new { Status = status } )); }
public IActionResult Insert(Employee model) { if (ModelState.IsValid) { _repositoryManager.Employee.CreateEmployeeForCompany(model.CompanyId, model); _repositoryManager.Save(); ViewBag.Message = "Werknemer toegevoegd"; } FillCompanies(); return(View(model)); }
public IActionResult DeleteCompany(Guid id) { var company = _repositoryManager.Company.GetCompany(id, false); //no trackchanges if (company == null) { return(NotFound()); } _repositoryManager.Company.DeleteCompany(company); _repositoryManager.Save(); return(NoContent()); //204 alles dat met 2 begint is goed }
public IActionResult DeleteEmployee(Guid id) { var employee = _repositoryManager.Employee.GetEmployee(id, false); //no trackchanges if (employee == null) { return(NotFound()); } _repositoryManager.Employee.DeleteEmployee(employee); _repositoryManager.Save(); return(NoContent()); }