public IEnumerable<dynamic> GetRequiredTrainings(int Id = 0) { if (Id == 0) { Id = SessionModel.UserID; } TrainingEntities entities = new TrainingEntities(); IEnumerable<group> userGroups = UserModel.GetGroups(Id); var trainings = entities.phases.AsEnumerable() .Where(phase => phase.trainings.Any(training => training.groups.Intersect(userGroups).Count() > 0)) .Select(phase => new { name = phase.name, trainings = phase.trainings.AsEnumerable() .Where(training => training.groups.Intersect(userGroups).Count() > 0) .Select(training => new { topic = training.topic, description = training.description, duration = training.duration }) }); return trainings.ToList(); }
public IHttpActionResult Post([FromBody] TrainingData training) { try { if (training == null) { return(BadRequest("Request had paramters")); } DateTime startDate = (DateTime)training.StartDate; DateTime endDate = (DateTime)training.EndDate; int days = (endDate - startDate).Days; using (TrainingEntities entities = new TrainingEntities()) { entities.TrainingDatas.Add(training); entities.SaveChanges(); } return(Ok(days)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IEnumerable<dynamic> GetCompletedTrainings(int Id = 0) { if (Id == 0) { Id = SessionModel.UserID; } TrainingEntities entities = new TrainingEntities(); var trainings = entities.phases.AsEnumerable() .Where(phase => phase.trainings.Any(training => training.training_schedule.Any(schedule => schedule.users_training.Any(userTraining => userTraining.user_id == Id && userTraining.status.name == "COMPLETE")))) .Select(phase => new { name = phase.name, trainings = phase.trainings.AsEnumerable() .Where(training => training.training_schedule.Any(schedule => schedule.users_training.Any(userTraining => userTraining.user_id == Id && userTraining.status.name == "COMPLETE"))) .Select(training => new { topic = training.topic, description = training.description, duration = training.duration }) }); return trainings.ToList(); }
/// <summary> /// Get an enumerable list of all groups associated with the given user. /// </summary> /// <param name="UserID">ID of the user to get the groups for.</param> /// <returns>Enumerable list of group object.</returns> public static IEnumerable<group> GetGroups( int UserID ) { TrainingEntities entities = new TrainingEntities(); var user = entities.users.AsEnumerable() .First(curUser => curUser.id == UserID); IEnumerable<group> userGroups = user.groups; foreach (group userGroup in user.groups) { userGroups = GetParentGroups(userGroup, true).Concat<group>(userGroups); } return userGroups; }
public IHttpActionResult PostNewEmployee(EmployeeModel employee) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new TrainingEntities()) { ctx.Employees.Add( new Employee { EmployeeId = employee.EmployeeId, EmployeeName = employee.EmployeeName, EmployeeRole = employee.EmployeeRole, DepartmentId = employee.DepartmentId }); // employees.Add(employee); ctx.SaveChanges(); } return(Ok()); }
public dynamic Login([FromBody]UserModel credentials) { TrainingEntities entities = new TrainingEntities(); var user = entities.users.AsEnumerable() .First(curUser => curUser.email.Trim() == credentials.Email.Trim()); if (user == null || user.password.Trim() != UserModel.Encrypt(credentials.Password).Trim()) { return new { id = 0 }; } SessionModel.UserID = user.id; return new { id = user.id, role = user.role.name, passwordReset = user.password_reset }; }
public dynamic UpdatePassword([FromBody]UserModel credentials) { TrainingEntities entities = new TrainingEntities(); var user = entities.users.AsEnumerable() .First(curUser => curUser.id == SessionModel.UserID); if (user == null) { return new { success = false }; } user.password = UserModel.Encrypt(credentials.Password); user.password_reset = 0; entities.SaveChanges(); return new { success = true }; }
/// /// Constructor used by Moq /// /// Repository public TrainingController(TrainingEntities mockDB) { this.objEntity = mockDB; }
/// /// Default constructor /// public TrainingController() { this.objEntity = new TrainingEntities(); }