public UserModel CreateUser(UserQueryModel userQuery)
 {
     var status = new GeneralStatus
     {
         StatusName = userQuery.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     db.GeneralStatuses.Add(status);
     UserModel result = new UserModel();
     var user = new User { UserName = userQuery.UserName, Email = userQuery.Email, StatusId = status.StatusId };
     db.Users.Add(user);
     db.SaveChanges();
     result = new UserModel
     {
         Id = user.UserId,
         UserName = user.UserName,
         Email = user.Email,
         Status = user.Status
     };
     return result;
 }
 public FacultyModel AddFaculty(FacultyModel faculty)
 {
     var result = new FacultyModel();
     var status = new GeneralStatus
     {
         StatusName = faculty.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     DbContext.GeneralStatuses.Add(status);
     var newFaculty = new Faculty
     {
         FacultyName = faculty.FacultyName,
         Note = faculty.Note,
         GeneralStatusId = status.StatusId,
         DirectorId = faculty.DirectorId,
         ProViceId = faculty.ProViceId
     };
     DbContext.Faculties.Add(newFaculty);
     DbContext.SaveChanges();
     result.FacultyId = newFaculty.FacultyId;
     return result;
 }
 public ApiSimpleResult<UserRole> CreateUserRole(UserRoleModel userRole)
 {
     var result = new ApiSimpleResult<UserRole>() { StatusString = "Fail", Message = "Cannot create user role." };
     if (userRole != null)
     {
         var status = new GeneralStatus
         {
             StatusName = userRole.Status,
             CreateTime = DateTime.Now,
             UpdateTime = DateTime.Now
         };
         db.GeneralStatuses.Add(status);
         var newUserRole = new UserRole
         {
             RoleId = userRole.RoleId,
             UserId = userRole.UserId,
             Note = userRole.Note,
             StatusId = status.StatusId
         };
         db.UserRoles.Add(newUserRole);
         db.SaveChanges();
         result.StatusString = "Succesful";
         result.Message = "Create new UserRole successfully";
         result.Data = newUserRole;
     }
     return result;
 }
 public RoleModel CreateRole(RoleModelQuery roleModelQuery)
 {
     RoleModel result = new RoleModel();
     var status = new GeneralStatus
     {
         StatusName = roleModelQuery.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     db.GeneralStatuses.Add(status);
     var role = new Role
     {
         RoleName = roleModelQuery.RoleName,
         StatusId = status.StatusId,
         Note = roleModelQuery.Note
     };
     db.Roles.Add(role);
     db.SaveChanges();
     result = new RoleModel
     {
         RoleId = role.RoleId,
         RoleName = role.RoleName,
     };
     return result;
 }
 public StudentCourseModel AddStudentCourse(StudentCourseModel queryModel)
 {
     var result = new StudentCourseModel();
     var status = new GeneralStatus
     {
         StatusName = queryModel.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     DbContext.GeneralStatuses.Add(status);
     var newItem = new StudentCourse
     {
         StudentId = queryModel.StudentId,
         CourseId = queryModel.CourseId,
         Mark = queryModel.Mark,
         Comment = queryModel.Comment,
         GradeGroupId = queryModel.GradeGroupId,
         GeneralStatusId = status.StatusId
     };
     DbContext.StudentCourses.Add(newItem);
     DbContext.SaveChanges();
     result.StudentCourseId = newItem.StudentCourseId;
     return result;
 }
 public StudentModel AddStudent(StudentModel queryModel)
 {
     var result = new StudentModel();
     var status = new GeneralStatus
     {
         StatusName = queryModel.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     DbContext.GeneralStatuses.Add(status);
     var newItem = new Student
     {
         StudentCode = queryModel.StudentCode,
         FullName = queryModel.FullName,
         Address = queryModel.Address,
         PhoneNumber = queryModel.PhoneNumber,
         DateOfBirth = queryModel.DateOfBirth,
         Email = queryModel.Email,
         GeneralStatusId = status.StatusId
     };
     DbContext.Students.Add(newItem);
     DbContext.SaveChanges();
     result.StudentId = newItem.StudentId;
     return result;
 }
 public FacultyCourseModel AddFacultyCourse(FacultyCourseModel facultyCourse)
 {
     var result = new FacultyCourseModel();
     var status = new GeneralStatus
     {
         StatusName = facultyCourse.Status,
         CreateTime = DateTime.Now,
         UpdateTime = DateTime.Now
     };
     DbContext.GeneralStatuses.Add(status);
     var newItem = new FacultyCourse
     {
         FacultyId = facultyCourse.FacultyId,
         CourseId = facultyCourse.CourseId,
         Note = facultyCourse.Note,
         GeneralStatusId = status.StatusId
     };
     DbContext.FacultyCourses.Add(newItem);
     DbContext.SaveChanges();
     result.FacultyCourseId = newItem.FacultyCourseId;
     return result;
 }