コード例 #1
0
ファイル: Database.cs プロジェクト: Cognite-Soft/ARB_2016_V2
        public void UpdateCase(CaseData caseData)
        {
            using (var context = new DatabaseContext())
            {
                var entity = context.Cases.FirstOrDefault(c => c.Id == caseData.Id);
                if (entity == null) throw new Facade.CaseDoesNotExistsException();

                entity.Status = (CaseEntity.CaseStatus) caseData.Status;
                entity.StartDate = caseData.StartDate;
                entity.Background = caseData.Background;
                entity.IdealOutcome = caseData.IdealOutcome;
                entity.IssueRaisedWithArchitect = new CaseEntity.Question
                {
                    Answer = caseData.IssueRaisedWithArchitect.Answer,
                    Comments = caseData.IssueRaisedWithArchitect.Comments,
                };
                entity.SubjectOfLegalProceedings = new CaseEntity.Question
                {
                    Answer = caseData.SubjectOfLegalProceedings.Answer,
                    Comments = caseData.SubjectOfLegalProceedings.Comments,
                };
                entity.Relationship = caseData.Relationship;
                entity.ContactAgreement = caseData.ContactAgreement;
                entity.ClaimantContact = new CaseEntity.Contact
                {
                    Address = caseData.ClaimantContact.Address,
                    EMail = caseData.ClaimantContact.EMail,
                    Name = caseData.ClaimantContact.Name,
                    Phone = caseData.ClaimantContact.Phone,
                };
                entity.ArchitectContact = new CaseEntity.Contact
                {
                    Address = caseData.ArchitectContact.Address,
                    EMail = caseData.ArchitectContact.EMail,
                    Name = caseData.ArchitectContact.Name,
                    Phone = caseData.ArchitectContact.Phone,
                    RegistrationNumber = caseData.ArchitectContact.RegistrationNumber,
                };
                entity.ProcessStartDate = caseData.ProcessStartDate;

                context.SaveChanges();
            }
        }
コード例 #2
0
ファイル: Database.cs プロジェクト: Cognite-Soft/ARB_2016_V2
        public CaseData GetCaseById(int id)
        {
            using (var context = new DatabaseContext())
            {
                var entity = context.Cases.
                    Include(item => item.DatesAndDetails).
                    Include(item => item.Allegations).
                    Include(item => item.AssignedUsers).
                    FirstOrDefault(item => item.Id == id);
                if (entity == null) return null;

                var result = new CaseData
                {
                    Id = entity.Id,
                    ParentId = entity.ParentId,
                    Status = (CaseData.CaseStatus) entity.Status,
                    StartDate = entity.StartDate,
                    Background = entity.Background,
                    IdealOutcome = entity.IdealOutcome,
                    IssueRaisedWithArchitect = new CaseData.Question
                    {
                        Answer = entity.IssueRaisedWithArchitect.Answer,
                        Comments = entity.IssueRaisedWithArchitect.Comments,
                    },
                    SubjectOfLegalProceedings = new CaseData.Question
                    {
                        Answer = entity.SubjectOfLegalProceedings.Answer,
                        Comments = entity.SubjectOfLegalProceedings.Comments,
                    },
                    Relationship = entity.Relationship,
                    ContactAgreement = entity.ContactAgreement,
                    ClaimantContact = new CaseData.ContactData
                    {
                        Name = entity.ClaimantContact.Name,
                        EMail = entity.ClaimantContact.EMail,
                        Address = entity.ClaimantContact.Address,
                        Phone = entity.ClaimantContact.Phone,
                    },
                    ArchitectContact = new CaseData.ArchitectContactData
                    {
                        Name = entity.ArchitectContact.Name,
                        RegistrationNumber = entity.ArchitectContact.RegistrationNumber,
                        EMail = entity.ArchitectContact.EMail,
                        Address = entity.ArchitectContact.Address,
                        Phone = entity.ArchitectContact.Phone,
                    },
                    AssignedUsers = entity.AssignedUsers.Select(item => new UserHeader
                    {
                        Id = item.Id,
                        Email = item.Email,
                        FirstName = item.FirstName,
                        LastName = item.LastName,
                        Role = item.Role,
                    }).ToArray(),
                    DatesAndDetails = entity.DatesAndDetails.OrderBy(x => x.Date).ThenBy(x => x.Order)
                        .Select(item => new CaseData.DatesAndDetail
                        {
                            Id = item.Id,
                            Date = item.Date,
                            Text = item.Text,
                            Documents = item.Documents.Select(d => new CaseData.Document {Id = d.Id, Name = d.Name}),
                        }).ToArray(),
                    Allegations = entity.Allegations
                        .OrderBy(item => item.Authorship.Date).ThenBy(item => item.Order)
                        .Select(item => new CaseData.Allegation
                        {
                            Id = item.Id,
                            Text = item.Text,
                            Documents = item.Documents.Select(d => new CaseData.Document {Id = d.Id, Name = d.Name}).ToArray(),
                            Comments = item.Comments.OrderByDescending(c => c.Authorship.Date).Select(c => new CaseData.Comment
                            {
                                CommentType = (CaseData.CommentType) c.Type,
                                Text = c.Text,
                                AdditionalText = c.AdditionalText,
                                PanelMemberId = c.Authorship.UserId,
                            }).ToArray(),
                        }).ToArray(),
                    ProcessStartDate = entity.ProcessStartDate,
                };

                result.PreliminaryDecisionDocument = entity.PreliminaryDecisionDocument == null
                    ? null
                    : new CaseData.Document
                    {
                        Id = entity.PreliminaryDecisionDocument.Id,
                        Name = entity.PreliminaryDecisionDocument.Name
                    };
                result.FinalDecisionDocument = entity.FinalDecisionDocument == null
                    ? null
                    : new CaseData.Document
                    {
                        Id = entity.FinalDecisionDocument.Id,
                        Name = entity.FinalDecisionDocument.Name
                    };

                return result;
            }
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 public void CreateCase(CaseData caseData)
 {
     using (var context = new DatabaseContext())
     {
         var newCase = new CaseEntity
         {
             Id = caseData.Id,
             ParentId = caseData.ParentId,
             Status = (CaseEntity.CaseStatus) caseData.Status,
             StartDate = caseData.StartDate,
             Background = caseData.Background,
             IdealOutcome = caseData.IdealOutcome,
             IssueRaisedWithArchitect = new CaseEntity.Question
             {
                 Answer = caseData.IssueRaisedWithArchitect.Answer,
                 Comments = caseData.IssueRaisedWithArchitect.Comments,
             },
             SubjectOfLegalProceedings = new CaseEntity.Question
             {
                 Answer = caseData.SubjectOfLegalProceedings.Answer,
                 Comments = caseData.SubjectOfLegalProceedings.Comments,
             },
             Relationship = caseData.Relationship,
             ContactAgreement = caseData.ContactAgreement,
             ClaimantContact = new CaseEntity.Contact
             {
                 Name = caseData.ClaimantContact.Name,
                 EMail = caseData.ClaimantContact.EMail,
                 Address = caseData.ClaimantContact.Address,
                 Phone = caseData.ClaimantContact.Phone,
             },
             ArchitectContact = new CaseEntity.Contact
             {
                 Name = caseData.ArchitectContact.Name,
                 RegistrationNumber = caseData.ArchitectContact.RegistrationNumber,
                 EMail = caseData.ArchitectContact.EMail,
                 Address = caseData.ArchitectContact.Address,
                 Phone = caseData.ArchitectContact.Phone,
             },
         };
         context.Cases.Add(newCase);
         context.SaveChanges();
     }
 }
コード例 #4
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private static void ForbidUnassignedUser(UserHeader user, CaseData @case)
 {
     if (@case.AssignedUsers.All(u => u.Id != user.Id)) throw new ForbiddenException();
 }
コード例 #5
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
        public void ReopenCase(int caseId)
        {
            using (var transaction = new TransactionScope())
            {
                var @case = _database.GetCaseById(caseId);
                if (@case == null) throw new CaseDoesNotExistException();
                var caseManager = @case.AssignedUsers.FirstOrDefault(x => x.Role == Role.CaseWorker);

                int nextCaseId = GetNextCaseId(caseId);

                var newCase = new CaseData
                {
                    Id = nextCaseId,
                    ParentId = caseId,
                    Status = CaseData.CaseStatus.New,
                    Background = @case.Background,
                    IdealOutcome = @case.IdealOutcome,
                    Relationship = @case.Relationship,
                    ContactAgreement = @case.ContactAgreement,
                    StartDate = DateTime.Now,
                    IssueRaisedWithArchitect = @case.IssueRaisedWithArchitect,
                    SubjectOfLegalProceedings = @case.SubjectOfLegalProceedings,
                    ArchitectContact = @case.ArchitectContact,
                    ClaimantContact = @case.ClaimantContact,
                };
                _database.CreateCase(newCase);
                if (caseManager != null)
                    AssignCaseWorker(newCase.Id, caseManager);
                AutoAssignPanelMembers(newCase);
                transaction.Complete();
            }
        }
コード例 #6
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private static void ForbidSecondComment(UserHeader user, CaseData.Allegation allegation)
 {
     if (allegation.Comments.Any(c => c.PanelMemberId == user.Id)) throw new ForbiddenException();
 }
コード例 #7
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private void ForbidNotPreliminaryCommentsCaseState(CaseData @case)
 {
     var status = GetCaseState(@case);
     if (status.StateKind != CaseStateKind.PriliminaryComments) throw new ForbiddenException();
 }
コード例 #8
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
        private CasePanelMembers GetPanelMembers(CaseData caseData)
        {
            var panelMembers = caseData.AssignedUsers.Where(user => user.Role == Role.PanelMember).ToArray();

            return new CasePanelMembers
            {
                PanelMember1 = panelMembers.FirstOrDefault(),
                PanelMember2 = panelMembers.Skip(1).FirstOrDefault(),
                PanelMember3 = panelMembers.Skip(2).FirstOrDefault(),
            };
        }
コード例 #9
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private CaseState GetCaseState(CaseData caseData)
 {
     if (!caseData.StartDate.HasValue && caseData.Status != CaseData.CaseStatus.New)
         throw new Exception("incorrect invariant: case start date can't be null when status is not draft");
     const int weeks = 7;
     var status = caseData.Status;
     var startDate = caseData.StartDate.Value;
     switch (status)
     {
         case CaseData.CaseStatus.New:
         {
             var dueBy = startDate == null ? (DateTime?) null : startDate.AddDays(4*weeks);
             var daysLeft = startDate == null ? null : (int?) (dueBy.Value - DateTime.Today).TotalDays;
             return new CaseState
             {
                 StateKind = CaseStateKind.New,
                 DueByDate = dueBy,
                 DueDaysLeft = daysLeft,
             };
         }
         case CaseData.CaseStatus.Open:
         {
             var today = DateTime.Today;
             var timeSpan = today - startDate;
             var totalDays = timeSpan.TotalDays;
             if (totalDays <= 4*weeks)
             {
                 var dueBy = startDate.AddDays(4*weeks);
                 return new CaseState
                 {
                     StateKind = CaseStateKind.PriliminaryComments,
                     DueByDate = dueBy,
                     DueDaysLeft = (int?) (dueBy - today).TotalDays,
                 };
             }
             else if (totalDays <= 4*weeks + 1*weeks)
             {
                 var dueBy = startDate.AddDays(4*weeks + 1*weeks);
                 return new CaseState
                 {
                     StateKind = CaseStateKind.PriliminaryDecision,
                     DueByDate = dueBy,
                     DueDaysLeft = (int?) (dueBy - today).TotalDays,
                 };
             }
             else if (totalDays <= 4*weeks + 3*weeks)
             {
                 var dueBy = startDate.AddDays(4*weeks + 3*weeks);
                 return new CaseState
                 {
                     StateKind = CaseStateKind.WaitingForPartyComments,
                     DueByDate = dueBy,
                     DueDaysLeft = (int?) (dueBy - today).TotalDays,
                 };
             }
             else if (totalDays <= 4*weeks + 3*weeks + 1*weeks)
             {
                 var dueBy = startDate.AddDays(4*weeks + 3*weeks + 1*weeks);
                 return new CaseState
                 {
                     StateKind = CaseStateKind.FinalDecision,
                     DueByDate = dueBy,
                     DueDaysLeft = (int?) (dueBy - today).TotalDays,
                 };
             }
             else // if (totalDays < 4 * weeks + 3 * weeks + 5 * weeks)
             {
                 var dueBy = startDate.AddDays(4*weeks + 3*weeks + 5*weeks);
                 return new CaseState
                 {
                     StateKind = CaseStateKind.Locked,
                     DueByDate = dueBy,
                     DueDaysLeft = (int?) (dueBy - today).TotalDays,
                 };
             }
         }
         case CaseData.CaseStatus.Closed:
             return new CaseState
             {
                 StateKind = CaseStateKind.Closed,
                 DueByDate = null,
                 DueDaysLeft = null,
             };
         case CaseData.CaseStatus.Rejected:
             return new CaseState
             {
                 StateKind = CaseStateKind.Rejected,
                 DueByDate = null,
                 DueDaysLeft = null,
             };
         default:
             throw new Exception("Unknown case status");
     }
 }
コード例 #10
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private bool IsQuestionNotAnswered(CaseData.Question question)
 {
     return question == null || question.Answer == null || question.Comments == null;
 }
コード例 #11
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private bool GetIsCaseReadyToStart(CaseData @case)
 {
     return !(@case.StartDate == null
              || string.IsNullOrEmpty(@case.Background) || string.IsNullOrEmpty(@case.IdealOutcome)
              || IsQuestionNotAnswered(@case.IssueRaisedWithArchitect)
              || IsQuestionNotAnswered(@case.SubjectOfLegalProceedings));
 }
コード例 #12
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
        public void CreateCase(CreateCaseInfo @case, string caseWorkerEmail)
        {
            using (var transaction = new TransactionScope())
            {
                var caseWorker = _database.GetUserByEmail(caseWorkerEmail);

                var existingCase = _database.GetCaseById(@case.Id);
                if (existingCase != null) throw new DuplicateCaseIdException();

                var newCase = new CaseData
                {
                    Id = @case.Id,
                    ParentId = null,
                    Status = CaseData.CaseStatus.New,
                    Background = null,
                    IdealOutcome = null,
                    Relationship = null,
                    ContactAgreement = null,
                    StartDate = @case.StartDate,
                    IssueRaisedWithArchitect = new CaseData.Question(),
                    SubjectOfLegalProceedings = new CaseData.Question(),
                    ArchitectContact = new CaseData.ArchitectContactData(),
                    ClaimantContact = new CaseData.ContactData
                    {
                        Name = @case.ClaimantContact.Name,
                        Address = @case.ClaimantContact.Address,
                        EMail = @case.ClaimantContact.EMail,
                        Phone = @case.ClaimantContact.Phone,
                    },
                };
                _database.CreateCase(newCase);
                if (caseWorker != null)
                    AssignCaseWorker(newCase.Id, caseWorker);
                AutoAssignPanelMembers(newCase);

                transaction.Complete();
            }
        }
コード例 #13
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private static bool IsUserAssignedToCase(UserHeader user, CaseData caseData)
 {
     return caseData.AssignedUsers.Any(item => item.Id == user.Id);
 }
コード例 #14
0
ファイル: Facade.cs プロジェクト: Cognite-Soft/ARB_2016_V2
 private void AutoAssignPanelMembers(CaseData caseData)
 {
     var panelMembersAssigned = caseData.AssignedUsers != null &&
                                caseData.AssignedUsers.Any(u => u.Role == Role.PanelMember);
     if (panelMembersAssigned) return;
     var schedules = _database.GetSchedules();
     var filledSchedules = schedules.Where(s => s.First != null && s.Second != null && s.Third != null).ToArray();
     var orderedSchedules = filledSchedules.OrderBy(s => s.LastUsed).ToArray();
     var nextSchedule = orderedSchedules.FirstOrDefault();
     if (nextSchedule == null) return;
     _database.AssignUser(caseData.Id, nextSchedule.First.Id);
     _database.AssignUser(caseData.Id, nextSchedule.Second.Id);
     _database.AssignUser(caseData.Id, nextSchedule.Third.Id);
     nextSchedule.LastUsed = DateTime.Now;
     _database.UpdateSchedule(nextSchedule);
 }