public void CreateAssignment(AssignmentRequest request) { using (var connection = factory.Connect()) { connection.Open(); using (var transaction = connection.BeginTransaction()) { try { var assignmentGuid = Guid.NewGuid(); CreateAssignment(assignmentGuid, request, connection, transaction); AddTrainingMaterials(assignmentGuid, request.TrainingMaterials, connection, transaction); if (request.AssignedTo == AssignedTo.SelectedSquads) { AssignToSquads(assignmentGuid, request, connection, transaction); } else { AssignToPlayers(assignmentGuid, request, connection, transaction); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }
public static void ProcessWorkflow(RigOapChecklist rigOapChecklist, ILog log, IIrmaOapDbContext context) { var wfs = new WorkflowEngineService(log); var wfir = new RigOapChecklistWorkflowRepository(context, log); var peopler = new PeopleRepository(context, log); var workflowActivity = new Genericlist() { DisplayName = $"Genericlist_{rigOapChecklist.Id}" }; var workflowinstance = wfir.GetWorkflowByChecklist(rigOapChecklist.Id); var people = new List <Person>() { peopler.Get(rigOapChecklist.OwnerId) }; var request = new AssignmentRequest() { Users = people }; wfs.Process(workflowActivity, new Version(workflowinstance.Workflow.Major, workflowinstance.Workflow.Minor), workflowinstance, workflowinstance.Transition, request); }
public async Task Put(int id, AssignmentRequest request) { var model = await _repository.GetByIdAsync(id); model.Title = request.Title; model.Text = request.Text; await _repository.Put(model); }
public async Task <AssignmentVm> GetById(AssignmentRequest request) { var data = await _context.Assignments .Where(x => x.ModuleID == request.ModuleID && x.ClassId == request.ClassId && x.TrainerID == request.TrainerID) .Include(x => x.Class).Include(x => x.Module).Include(x => x.Trainer) .FirstOrDefaultAsync(); return(_mapper.Map <AssignmentVm>(data)); }
public async Task <IActionResult> EditAssignment([FromBody] AssignmentRequest request) { Assignment temp = _mapper.Map <Assignment>(request); if (await _assignmentService.EditAssignment(temp)) { return(Ok("Successful")); } return(BadRequest("Assignment Is Exist")); }
public async Task <IActionResult> GetById(int classId, int moduleId, string trainerId) { AssignmentRequest request = new AssignmentRequest() { ClassId = classId, ModuleID = moduleId, TrainerID = trainerId }; return(Ok(await _assignmentService.GetById(request))); }
private void UpdateAssignment(Assignment existingAssignment, AssignmentRequest newAssignment) { if (existingAssignment.IsOwner) { return; } existingAssignment.Deadline = newAssignment.Deadline; existingAssignment.CanRead = newAssignment.CanRead; existingAssignment.CanWrite = newAssignment.CanWrite; existingAssignment.CanChangeAccess = newAssignment.CanChangeAccess; }
public async Task <ActionResult> put(int id, [FromBody] AssignmentRequest request) { try { await _manager.Put(id, request); return(NoContent()); }catch (Exception ex) { ex.Message.ToString(); return(BadRequest()); } }
public async Task <ActionResult <Assignment> > postAsync([FromBody] AssignmentRequest request) { try { var model = await _manager.postAsync(request); return(Ok(model)); } catch (Exception ex) { ex.Message.ToString(); return(BadRequest()); } }
public async Task <Assignment> postAsync(AssignmentRequest request) { Assignment model = new Assignment(); model.Title = request.Title; model.Text = request.Text; model.Teacher = await _teacher.GetByEmail(request.Teacher); model.Classroom = await _classroom.GetByIdAsync(request.ClassroomId); var newModel = await _repository.PostAsync(model); return(_repository.Find(x => x.Id == newModel.Id, x => x.Classroom, x => x.Teacher)); }
private static void CreateAssignment(Guid guid, AssignmentRequest request, IDbConnection connection, IDbTransaction transaction) { var sql = @"INSERT INTO Assignments(Guid, ClubId, CreatedOn, CoachId, Title, Instructions, DueDate) SELECT @AssignmentGuid, Cl.ClubId, GetDate(), Co.CoachId, @Title, @Instructions, @DueDate FROM Clubs Cl INNER JOIN Coaches Co ON Co.ClubId = Cl.ClubId WHERE Co.Guid = @CoachGuid AND Cl.Guid = @ClubGuid;"; var parameters = new DynamicParameters(); parameters.Add("@AssignmentGuid", guid); parameters.Add("@ClubGuid", request.ClubId); parameters.Add("@CoachGuid", request.CoachId); parameters.Add("@Title", request.Title); parameters.Add("@Instructions", request.Instructions); parameters.Add("@DueDate", request.DueDate); connection.Execute(sql, parameters, transaction); }
private void AssignToSquads(Guid assignmentGuid, AssignmentRequest request, IDbConnection connection, IDbTransaction transaction) { var sql = @"INSERT INTO PlayerAssignments (PlayerId, AssignmentId, AssignedOn, CoachId) SELECT P.PlayerId, (SELECT AssignmentId FROM Assignments WHERE Guid = @AssignmentGuid), GetDate(), (Select CoachId FROM Coaches WHERE Guid = @CoachGuid) FROM Players P INNER JOIN Squads S ON P.SquadId = S.SquadId WHERE S.Guid IN @Squads AND (P.Deleted IS NULL OR P.Deleted = 0);"; var parameters = new DynamicParameters(); parameters.Add("@AssignmentGuid", assignmentGuid); parameters.Add("@Squads", request.Squads); parameters.Add("@CoachGuid", request.CoachId); connection.Execute(sql, parameters, transaction); }
public AddAssignments() { _assignmentRequest = new AssignmentRequest { UserId = _user.Id, CanChangeAccess = false, CanRead = false, CanWrite = false, Deadline = DateTime.Now, IsOwner = false }; _request = new AddOrUpdateAssignmentsRequest { TaskId = _task.Id, Assignments = new AssignmentRequest[] { _assignmentRequest } }; }
private void AssignToPlayers(Guid assignmentGuid, AssignmentRequest request, IDbConnection connection, IDbTransaction transaction) { var sql = $@"INSERT INTO PlayerAssignments (PlayerId, AssignmentId, AssignedOn, CoachId) SELECT P.PlayerId, (SELECT AssignmentId FROM Assignments WHERE Guid = @AssignmentGuid), GetDate(), (Select CoachId FROM Coaches WHERE Guid = @CoachGuid) FROM Players P {(request.AssignedTo == AssignedTo.IndividualPlayers ? "WHERE P.Guid IN @Players AND (P.Deleted IS NULL OR P.Deleted = 0) " : $@"INNER JOIN Squads S ON P.SquadId = S.SquadId INNER JOIN Clubs C ON S.ClubId = C.ClubId AND C.Guid = @ClubGuid" )};" ; var parameters = new DynamicParameters(); parameters.Add("@AssignmentGuid", assignmentGuid); parameters.Add("@Players", request.Players); parameters.Add("@CoachGuid", request.CoachId); parameters.Add("@ClubGuid", request.ClubId.ToString()); connection.Execute(sql, parameters, transaction); }
public async Task <IActionResult> AssignPermission([FromBody] AssignmentRequest request) { //TODO Implement many-to-many relationship so user could own more than one permission // TODO // Implement auto re-login to update claims info in the jwt // Or invalidate jwt so user must login again // one of the above solutions can avoid asking user obtain a new token and automatically applying permission on token var organisationID = HttpContext.GetOrganisationID(); var user = await _unitOfWork.UserRepository.GetWithDetailsAsync(request.UserID, organisationID); var policy = await _unitOfWork.PolicyRepository.GetByOrganisationAsync(request.PolicyName, organisationID); if (user == null || policy == null || user.Policy?.Name == policy.Name) { return(BadRequest(new ErrorResponse { Message = "Permission/User does not exist or already has the permission." })); } var transaction = _unitOfWork.UserRepository.BeginTransaction(); user.Policy = policy; await _unitOfWork.UserRepository.AddAsync(user); await _userManager.AddClaimAsync(user, new Claim(policy.Claim, "true")); transaction.Commit(); AssignmentResponse assignmentResponse = new AssignmentResponse { UserID = user.Id, PolicyName = policy.Name, Info = "Permission has been granted, please log-in again for the action to take effect." }; return(Ok(new Response <AssignmentResponse>(assignmentResponse))); }
public IActionResult Post([FromBody] AssignmentRequest request) { try { var response = new AssignmentResponse(request.Title); foreach (var assignment in request.Assignments) { var studentResult = new StudentResult(assignment.FirstName, assignment.LastName); response.StudentResults.Add(studentResult); if (assignment.Files == null) { continue; } foreach (var file in assignment.Files) { var source = Encoding.UTF8.GetString(Convert.FromBase64String(file.Base64Source)); var tree = CSharpSyntaxTree.ParseText(source); var root = (CompilationUnitSyntax)tree.GetRoot(); var tokens = root.DescendantTokens(); var tokenMap = new StudentTokenMap(file.FileName); studentResult.Files.Add(tokenMap); foreach (var token in tokens) { tokenMap.Tokens.Add(new TokenWithPosition(token.RawKind, token.FullSpan.Start, token.FullSpan.End)); } } } return(new ObjectResult(response)); } catch (Exception) { return(new BadRequestObjectResult("Invalid request format")); } }
public ActionResult <Unit> DenyTeamOnAssignment(AssignmentRequest request) { int? result = 0; string sqlQuery = $"DELETE FROM assignmentmember WHERE Id='{request.Id}' AND TeamId='{request.TeamId}' ;"; using (connection) { MySqlTransaction transaction = null; try { MySqlCommand command = new MySqlCommand(sqlQuery, connection); connection.Open(); transaction = connection.BeginTransaction(); command.Transaction = transaction; result = command.ExecuteNonQuery(); transaction.Commit(); } catch (Exception e) { Console.WriteLine(e.ToString()); transaction.Rollback(); connection.Close(); } connection.Close(); } if (result > 0) { return(Ok()); } return(Ok()); // throw new RestException(HttpStatusCode.NotFound); // throw new Exception("Problem"); }
public Response CreateAssignment(AssignmentRequest request) { var result = assignementRequestValidator.Validate(request); if (!result.IsValid) { return(Response.CreateResponse(result.Messages)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } var coach = memberQuery.GetCoach(request.CoachId); if (coach == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified coach does not exist"))); } else if (coach.ClubId != club.Guid) { return(Response.CreateResponse(new IllegalOperationException("The specified coach does not belong to this club"))); } var clubSquads = squadQuery.GetSquads(club.Guid); if (request.Squads?.Count() > 0) { var allOfRequestedSquadsBelongToClub = !request.Squads.Except(clubSquads.Select(s => s.Guid)).Any(); if (!allOfRequestedSquadsBelongToClub) { return(Response.CreateResponse(new IllegalOperationException("Not all of specified squads belong to this club"))); } } if (request.Players?.Count() > 0) { var members = memberQuery.GetMembers(clubSquads.Select(s => s.Guid)); var players = members.SelectMany(s => s.Members)?.Where(m => m.Membership.Equals("Player")); var allOfRequestedPlayersBelongToClub = !request.Players.Except(players.Select(p => p.Guid)).Any(); if (!allOfRequestedPlayersBelongToClub) { return(Response.CreateResponse(new IllegalOperationException("Not all of specified players belong to this club"))); } } if (request.TrainingMaterials?.Count() > 0) { var clubLibrary = libraryQuery.GetTrainingMaterials(request.ClubId); var allOfRequestedMaterialsBelongToClub = !request.TrainingMaterials.Except(request.TrainingMaterials).Any(); if (!allOfRequestedMaterialsBelongToClub) { return(Response.CreateResponse(new IllegalOperationException("Not all of specified training materials belong to this club"))); } } try { assignmentRepository.CreateAssignment(request); return(Response.CreateSuccessResponse()); }catch (Exception ex) { return(Response.CreateResponse(ex)); } }