示例#1
0
            public async Task <Result> Handle(Contract request, CancellationToken cancellationToken)
            {
                if (request.UserRole == "Secretary")
                {
                    return(Result.Fail("Acesso Negado"));
                }

                var evtId = ObjectId.Parse(request.EventId);

                var evt = await _db.EventDraftCollection.AsQueryable()
                          .Where(x => (
                                     x.DeletedAt == null || x.DeletedAt == DateTimeOffset.MinValue
                                     ) && !x.DraftPublished && (
                                     x.Id == evtId || x.EventId == evtId
                                     )
                                 )
                          .FirstOrDefaultAsync(cancellationToken: cancellationToken);

                if (evt == null)
                {
                    var originalEvent = await GetEvent(request.EventId);

                    if (originalEvent == null)
                    {
                        return(Result.Fail("Evento não existe"));
                    }

                    evt = await CreateEventDraft(
                        request, originalEvent, cancellationToken
                        );
                }

                var results = request.Requirements.Select(x =>
                                                          Requirement.Create(
                                                              ObjectId.Parse(x.ModuleId),
                                                              x.Optional,
                                                              x.Level,
                                                              x.Percentage,
                                                              ProgressType.ModuleProgress
                                                              )
                                                          ).ToArray();

                var combinedResults = Result.Combine(results);

                if (combinedResults.IsFailure)
                {
                    return(Result.Fail(combinedResults.Error));
                }

                evt.Requirements = results.Select(x => x.Data).ToList();

                await _db.EventDraftCollection.ReplaceOneAsync(t =>
                                                               t.Id == evt.Id, evt,
                                                               cancellationToken : cancellationToken
                                                               );

                return(Result.Ok());
            }
示例#2
0
            public async Task <Result <bool> > Handle(Contract request, CancellationToken cancellationToken)
            {
                if (request.UserRole == "Secretary")
                {
                    return(Result.Fail <bool>("Acesso Negado"));
                }

                var mId    = ObjectId.Parse(request.ModuleId);
                var module = await(await _db
                                   .Database
                                   .GetCollection <Module>("Modules")
                                   .FindAsync(x => x.Id == mId, cancellationToken: cancellationToken))
                             .FirstOrDefaultAsync(cancellationToken: cancellationToken);

                if (module == null)
                {
                    return(Result.Fail <bool>("Módulo não Encontrado"));
                }

                if (request.UserRole == "Student")
                {
                    var userId = ObjectId.Parse(request.UserId);

                    if (!Module.IsInstructor(module, userId).Data)
                    {
                        return(Result.Fail <bool>("Acesso Negado"));
                    }
                }

                var results = request.Requirements.Select(x => Requirement.Create(ObjectId.Parse(x.ModuleId),
                                                                                  x.Optional, x.Level, x.Percentage, ProgressType.ModuleProgress)).ToArray();

                var combinedResults = Result.Combine(results);

                if (combinedResults.IsFailure)
                {
                    return(Result.Fail <bool>(combinedResults.Error));
                }

                module.Requirements = results.Select(x => x.Data).ToList();

                await _db.ModuleCollection.ReplaceOneAsync(t =>
                                                           t.Id == module.Id, module,
                                                           cancellationToken : cancellationToken
                                                           );

                return(Result.Ok(true));
            }
示例#3
0
            public async Task<Result<bool>> Handle(Contract request, CancellationToken cancellationToken)
            {
                if (request.UserRole == "Secretary" || request.UserRole == "Recruiter")
                    return Result.Fail<bool>("Acesso Negado");

                var mId = ObjectId.Parse(request.EventId);
                var evt = await (await _db
                    .Database
                    .GetCollection<Event>("Events")
                    .FindAsync(x => x.Id == mId, cancellationToken: cancellationToken))
                    .FirstOrDefaultAsync(cancellationToken: cancellationToken);

                if (evt == null)
                    return Result.Fail<bool>("Evento não Encontrado");

                if (request.UserRole == "Student")
                {
                    var userId = ObjectId.Parse(request.UserId);

                    if (!evt.InstructorId.HasValue || evt.InstructorId.Value != userId)
                        return Result.Fail<bool>("Acesso Negado");
                }

                var results = request.Requirements.Select(x => 
                    Requirement.Create(
                        ObjectId.Parse(x.ModuleId),
                        x.Optional,
                        x.Level,
                        x.Percentage,
                        ProgressType.ModuleProgress
                    )
                ).ToArray();

                var combinedResults = Result.Combine(results);
                if (combinedResults.IsFailure)
                    return Result.Fail<bool>(combinedResults.Error);

                evt.Requirements = results.Select(x => x.Data).ToList();

                await _db.EventCollection.ReplaceOneAsync(t =>
                    t.Id == evt.Id, evt,
                    cancellationToken: cancellationToken
                );

                return Result.Ok(true);
            }
示例#4
0
            public async Task <Result> Handle(Contract request, CancellationToken cancellationToken)
            {
                if (request.UserRole == "Secretary")
                {
                    return(Result.Fail("Acesso Negado"));
                }

                var userId = ObjectId.Parse(request.UserId);
                var modId  = ObjectId.Parse(request.ModuleId);

                var module = await _db.ModuleDraftCollection.AsQueryable()
                             .Where(x => (
                                        x.DeletedAt == null || x.DeletedAt == DateTimeOffset.MinValue
                                        ) && !x.DraftPublished && (
                                        x.Id == modId || x.ModuleId == modId
                                        )
                                    )
                             .FirstOrDefaultAsync(cancellationToken: cancellationToken);

                var results = request.Requirements.Select(x =>
                                                          Requirement.Create(
                                                              ObjectId.Parse(x.ModuleId),
                                                              x.Optional, x.Level, x.Percentage,
                                                              ProgressType.ModuleProgress
                                                              )
                                                          ).ToArray();

                var combinedResults = Result.Combine(results);

                if (combinedResults.IsFailure)
                {
                    return(Result.Fail(combinedResults.Error));
                }

                var newRequirements = results.Select(x => x.Data).ToList();

                if (module == null)
                {
                    var originalModule = await GetModule(request.ModuleId);

                    if (originalModule == null)
                    {
                        return(Result.Fail("Módulo não existe"));
                    }

                    module = await CreateModuleDraft(
                        request, originalModule, newRequirements, cancellationToken
                        );

                    var newValues = new List <ModuleDraft>
                    {
                        module
                    };

                    var changeLog = AuditLog.Create(userId, module.Id, module.GetType().ToString(),
                                                    JsonConvert.SerializeObject(newValues), EntityAction.Add);

                    await _db.AuditLogCollection.InsertOneAsync(changeLog);
                }
                else
                {
                    var oldValues = JsonConvert.SerializeObject(new List <ModuleDraft>
                    {
                        module
                    });

                    module.Requirements = newRequirements;
                    await _db.ModuleDraftCollection.ReplaceOneAsync(t =>
                                                                    t.Id == module.Id, module,
                                                                    cancellationToken : cancellationToken
                                                                    );

                    var newDraftList = new List <ModuleDraft>
                    {
                        module
                    };

                    var changeLog = AuditLog.Create(userId, module.Id, module.GetType().ToString(),
                                                    JsonConvert.SerializeObject(newDraftList), EntityAction.Update, oldValues);

                    await _db.AuditLogCollection.InsertOneAsync(changeLog);
                }

                return(Result.Ok());
            }