Ejemplo n.º 1
0
        public Worker CreateWorker(CreateWorkerRequest createWorkerRequest)
        {
            if (GetWorkerByEmail(createWorkerRequest.EmailAddress) != null)
            {
                throw new PostWorkerException($"Worker with Email {createWorkerRequest.EmailAddress} already exists");
            }

            var worker = new Worker
            {
                Role           = createWorkerRequest.Role,
                Email          = createWorkerRequest.EmailAddress,
                FirstName      = createWorkerRequest.FirstName,
                LastName       = createWorkerRequest.LastName,
                IsActive       = true,
                CreatedBy      = createWorkerRequest.CreatedBy,
                ContextFlag    = createWorkerRequest.ContextFlag,
                DateStart      = createWorkerRequest.DateStart,
                DateEnd        = null,
                LastModifiedBy = createWorkerRequest.CreatedBy
            };

            var workerTeams = GetTeams(createWorkerRequest.Teams);

            worker.WorkerTeams = new List <WorkerTeam>();
            foreach (var team in workerTeams)
            {
                worker.WorkerTeams.Add(new WorkerTeam {
                    Team = team, Worker = worker
                });
            }

            _databaseContext.Workers.Add(worker);
            _databaseContext.SaveChanges();
            return(worker);
        }
 public static Worker ToDomain(this DbWorker worker, bool includeTeamData)
 {
     return(new Worker
     {
         Id = worker.Id,
         Email = worker.Email,
         FirstName = worker.FirstName,
         LastName = worker.LastName,
         Role = worker.Role,
         ContextFlag = worker.ContextFlag,
         CreatedBy = worker.CreatedBy,
         DateStart = worker.DateStart,
         AllocationCount = worker.Allocations?.Where(x => x.CaseStatus.ToUpper() == "OPEN").Count() ?? 0,
         Teams = (includeTeamData ? worker.WorkerTeams?.Select(x => new Team()
         {
             Id = x.Team.Id, Name = x.Team.Name, Context = x.Team.Context
         }).ToList() : null) ?? new List <Team>()
     });
 }
Ejemplo n.º 3
0
        public void PatchWarningNote(PatchWarningNoteRequest request)
        {
            WarningNote warningNote = _databaseContext.WarningNotes.FirstOrDefault(x => x.Id == request.WarningNoteId);

            if (warningNote == null)
            {
                throw new PatchWarningNoteException($"Warning Note with given id ({request.WarningNoteId}) not found");
            }

            if (warningNote.Status == "closed")
            {
                throw new PatchWarningNoteException(
                          $"Warning Note with given id ({request.WarningNoteId}) has already been closed");
            }

            Person person = _databaseContext.Persons.FirstOrDefault(x => x.Id == warningNote.PersonId);

            if (person == null)
            {
                throw new PatchWarningNoteException("Person not found");
            }

            Worker worker = _databaseContext.Workers.FirstOrDefault(x => x.Email == request.ReviewedBy);

            if (worker == null)
            {
                throw new PatchWarningNoteException($"Worker ({request.ReviewedBy}) not found");
            }


            warningNote.LastReviewDate = request.ReviewDate;
            warningNote.NextReviewDate = request.NextReviewDate;
            if (request.Status?.ToLower() == "closed")
            {
                warningNote.Status         = "closed";
                warningNote.EndDate        = _systemTime.Now;
                warningNote.NextReviewDate = null;
            }

            warningNote.LastModifiedBy = request.ReviewedBy;

            var review = PostWarningNoteReview(request);

            _databaseContext.WarningNoteReview.Add(review);
            _databaseContext.SaveChanges();

            var dt = DateTime.Now;

            var note = new WarningNoteCaseNote
            {
                FirstName       = person.FirstName,
                LastName        = person.LastName,
                MosaicId        = person.Id.ToString(),
                Timestamp       = dt.ToString("dd/MM/yyyy H:mm:ss"),
                Note            = $"{dt.ToShortDateString()} | Warning Note | {((request.Status == "closed") ? "Warning note against this person ended" : "Warning note against this person reviewed")}",
                FormNameOverall = "API_WarningNote",
                FormName        = (request.Status == "closed") ? "Warning Note Ended" : "Warning Note Reviewed",
                WarningNoteId   = warningNote.Id.ToString(),
                WorkerEmail     = request.ReviewedBy
            };

            var caseNotesDocument = new CaseNotesDocument
            {
                CaseFormData = JsonConvert.SerializeObject(note)
            };

            _ = _processDataGateway.InsertCaseNoteDocument(caseNotesDocument).Result;
        }