Skip to content

Instantly share code, notes, and snippets.

@JIOO-phoeNIX
Created January 2, 2021 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JIOO-phoeNIX/8d519a08f8d66d14a87e5f9e1db8b431 to your computer and use it in GitHub Desktop.
Save JIOO-phoeNIX/8d519a08f8d66d14a87e5f9e1db8b431 to your computer and use it in GitHub Desktop.
using GraphQLSampleApp.DataAccess.DAO;
using GraphQLSampleApp.DataAccess.Entity;
using HotChocolate;
using HotChocolate.Subscriptions;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GraphQLSampleApp.DataAccess
{
public class Mutation
{
public async Task<Department> CreateDepartment([Service]DepartmentRepository departmentRepository,
[Service]ITopicEventSender eventSender, string departmentName)
{
var newDepartment = new Department
{
Name = departmentName
};
var createdDepartment = await departmentRepository.CreateDepartment(newDepartment);
await eventSender.SendAsync("DepartmentCreated", createdDepartment);
return createdDepartment;
}
public async Task<Employee> CreateEmployeeWithDepartmentId([Service]EmployeeRepository employeeRepository,
string name, int age, string email, int departmentId)
{
Employee newEmployee = new Employee
{
Name = name,
Age = age,
Email = email,
DepartmentId = departmentId
};
var createdEmployee = await employeeRepository.CreateEmployee(newEmployee);
return createdEmployee;
}
public async Task<Employee> CreateEmployeeWithDepartment([Service] EmployeeRepository employeeRepository,
string name, int age, string email, string departmentName)
{
Employee newEmployee = new Employee
{
Name = name,
Age = age,
Email = email,
Department = new Department { Name = departmentName}
};
var createdEmployee = await employeeRepository.CreateEmployee(newEmployee);
return createdEmployee;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment