private bool SaveDeadLine(CaseDeadline deadline) { if (deadline != null) { if (workNotificationService.GetJudgeUserId(deadline.CaseId) == null) { return(false); } deadline.UserId = userContext.UserId; deadline.DateWrt = DateTime.Now; if ((deadline.CourtId ?? 0) <= 0) { deadline.CourtId = userContext.CourtId; } if (deadline.DateComplete == null && deadline.DateExpired == null) { var workNotification = workNotificationService.NewWorkNotification(deadline); if (workNotification != null) { workNotification.CaseDeadline = deadline; if (workNotification.Id == 0) { repo.Add(workNotification); } else { repo.Update(workNotification); } } else { if (deadline.Id == 0) { repo.Add(deadline); } else { repo.Update(deadline); } } return(true); } if (deadline.DateComplete != null || deadline.DateExpired != null) { if (deadline.Id == 0) { repo.Add(deadline); } else { repo.Update(deadline); } ExpireWorkNotifications(deadline); } } return(false); }
public WorkNotification NewWorkNotification(CaseDeadline caseDeadline) { var userId = GetJudgeUserId(caseDeadline.CaseId); if (userId == null) { return(null); } var workNotification = repo.AllReadonly <WorkNotification>() .Where(x => x.CaseDeadlineId == caseDeadline.Id && x.UserId == userId) .FirstOrDefault(); if (workNotification != null) { if (caseDeadline.DateComplete != null || caseDeadline.DateExpired != null) { if (workNotification.DateExpired == null) { workNotification.DateExpired = caseDeadline.DateExpired ?? caseDeadline.DateComplete; workNotification.UserExpiredId = userContext.UserId; return(workNotification); } } return(null); } var deadlineType = repo.AllReadonly <DeadlineType>() .Where(x => x.Id == caseDeadline.DeadlineTypeId) .FirstOrDefault(); deadlineType = deadlineType ?? new DeadlineType(); var aCase = repo.AllReadonly <Case>() .Where(x => x.Id == caseDeadline.CaseId) .FirstOrDefault(); if (aCase == null) { return(null); } var model = new WorkNotification(); model.SourceType = caseDeadline.SourceType; model.SourceId = caseDeadline.SourceId; model.WorkNotificationTypeId = NomenclatureConstants.WorkNotificationType.DeadLine; model.CaseDeadlineId = caseDeadline.Id; model.Title = $"Изтичащ срок по дело {aCase.RegNumber}"; model.Description = $"{deadlineType.Label} стартиран {caseDeadline.StartDate.ToString(FormattingConstant.NormalDateFormat)} изтичащ {caseDeadline.EndDate.ToString(FormattingConstant.NormalDateFormat)}"; model.LinkLabel = "Срок"; model.CourtId = aCase.CourtId; model.FromCourtId = userContext.CourtId; model.FromUserId = userContext.UserId; model.DateCreated = caseDeadline.EndDate.AddDays(-5); model.UserId = userId; return(model); }
private void ExpireWorkNotifications(CaseDeadline deadline) { var workNotifications = repo.AllReadonly <WorkNotification>() .Where(x => x.CaseDeadlineId == deadline.Id && x.DateExpired == null) .ToList(); foreach (var workNotification in workNotifications) { workNotification.DateExpired = deadline.DateExpired ?? deadline.DateComplete; workNotification.DescriptionExpired = deadline.DescriptionExpired; workNotification.UserExpiredId = deadline.UserExpiredId ?? deadline.UserId; repo.Update(workNotification); } }
public CaseDeadline DeadLineMotiveStart(CaseSessionAct sessionAct) { if (sessionAct.DateExpired != null || MotiveDateStart(sessionAct) == null || MotiveDateEnd(sessionAct) != null) { return(null); } var deadline = repo.AllReadonly <CaseDeadline>() .Where(x => x.SourceType == SourceTypeSelectVM.CaseSessionAct && x.SourceId == sessionAct.Id && x.DeadlineTypeId == NomenclatureConstants.DeadlineType.Motive) .FirstOrDefault(); var aCase = sessionAct.CaseSession?.Case; if (aCase == null) { var caseSession = sessionAct.CaseSession; if (caseSession == null) { caseSession = repo.AllReadonly <CaseSession>().Where(x => x.Id == sessionAct.CaseSessionId).FirstOrDefault(); } aCase = repo.AllReadonly <Case>().Where(x => x.Id == caseSession.CaseId).FirstOrDefault(); } var deadlineType = repo.AllReadonly <DeadlineType>().Where(x => x.Id == NomenclatureConstants.DeadlineType.Motive).FirstOrDefault(); if (deadline != null) { if (deadline.StartDate != MotiveDateStart(sessionAct)) { setUnExpired(deadline); deadline.StartDate = MotiveDateStart(sessionAct) ?? DateTime.Now; setDateEnd(deadline, deadlineType); } } else { deadline = new CaseDeadline(); deadline.CaseId = aCase.Id; deadline.SourceType = SourceTypeSelectVM.CaseSessionAct; deadline.SourceId = sessionAct.Id; deadline.DeadlineTypeId = NomenclatureConstants.DeadlineType.Motive; deadline.DeadlineGroupId = deadlineType.DeadlineGroupId; deadline.StartDate = MotiveDateStart(sessionAct) ?? DateTime.Now; setDateEnd(deadline, deadlineType); } return(deadline); }
private void setDateEnd(CaseDeadline deadline, DeadlineType deadlineType, bool isSpecial = false) { int?months = isSpecial ? deadlineType.DeadlineSpecialMonths : deadlineType.DeadlineMonths; if (months != null) { int month = months ?? 0; deadline.EndDate = deadline.StartDate.AddMonths(month).Date; while (!workingDaysService.IsWorkingDay(userContext.CourtId, deadline.EndDate)) { deadline.EndDate = deadline.EndDate.AddDays(1).Date; } } int?workingDays = isSpecial ? deadlineType.DeadlineSpecialWorkingDays : deadlineType.DeadlineWorkingDays; if (workingDays != null) { deadline.EndDate = deadline.StartDate.Date; int wDays = (workingDays ?? 0) - 1; while (wDays > 0) { deadline.EndDate = deadline.EndDate.AddDays(1); if (workingDaysService.IsWorkingDay(userContext.CourtId, deadline.EndDate)) { wDays--; } } } int?normalDays = isSpecial ? deadlineType.DeadlineSpecialDays : deadlineType.DeadlineDays; if (normalDays != null) { int days = normalDays ?? 0; deadline.EndDate = deadline.StartDate.AddDays(days - 1).Date; while (!workingDaysService.IsWorkingDay(userContext.CourtId, deadline.EndDate)) { deadline.EndDate = deadline.EndDate.AddDays(1).Date; } } }
public List <WorkNotification> NewWorkNotificationSecretary(CaseDeadline caseDeadline) { var result = new List <WorkNotification>(); if (caseDeadline.DeadlineTypeId != NomenclatureConstants.DeadlineType.OpenSessionResult) { return(result); } var deadlineType = repo.AllReadonly <DeadlineType>() .Where(x => x.Id == caseDeadline.DeadlineTypeId) .FirstOrDefault(); if (deadlineType == null) { return(result); } deadlineType = deadlineType ?? new DeadlineType(); var aCase = repo.AllReadonly <Case>() .Where(x => x.Id == caseDeadline.CaseId) .FirstOrDefault(); if (aCase == null) { return(result); } int caseSessionId = (int)caseDeadline.SourceId; var users = GetSessionMeetingSecretaryUserId(caseSessionId); foreach (string userId in users) { var workNotification = repo.AllReadonly <WorkNotification>() .Where(x => x.CaseDeadlineId == caseDeadline.Id && x.UserId == userId) .FirstOrDefault(); if (workNotification != null) { if (caseDeadline.DateComplete != null || caseDeadline.DateExpired != null) { if (workNotification.DateExpired == null) { workNotification.DateExpired = caseDeadline.DateExpired ?? caseDeadline.DateComplete; workNotification.UserExpiredId = userContext.UserId; result.Add(workNotification); } } continue; } var model = new WorkNotification(); model.SourceType = caseDeadline.SourceType; model.SourceId = caseDeadline.SourceId; model.WorkNotificationTypeId = NomenclatureConstants.WorkNotificationType.DeadLine; model.CaseDeadlineId = caseDeadline.Id; model.Title = $"Изтичащ срок по дело {aCase.RegNumber}"; model.Description = $"{deadlineType.Label} стартиран {caseDeadline.StartDate.ToString(FormattingConstant.NormalDateFormat)} изтичащ {caseDeadline.EndDate.ToString(FormattingConstant.NormalDateFormat)}"; model.LinkLabel = "Срок"; model.CourtId = aCase.CourtId; model.FromCourtId = userContext.CourtId; model.FromUserId = userContext.UserId; model.DateCreated = caseDeadline.EndDate.AddDays(-5); model.UserId = userId; result.Add(model); } return(result); }
private void setUnExpired(CaseDeadline deadline) { deadline.DateExpired = null; deadline.UserExpiredId = null; deadline.DescriptionExpired = ""; }
public List <CaseDeadline> DeadLineCompanyCaseStart(Case companyCase) { var result = new List <CaseDeadline>(); if (!nomService.CaseCodeGroup_Check(NomenclatureConstants.CaseCodeGroupAlias.CaseCompanyRegister, companyCase.CaseCodeId ?? 0)) { return(result); } var documents = repo.AllReadonly <DocumentCaseInfo>() .Where(x => x.CaseId == companyCase.Id) .Where(x => x.Document.DocumentTypeId == NomenclatureConstants.DocumentType.ApplicationForCompanyRegister || x.Document.DocumentTypeId == NomenclatureConstants.DocumentType.ApplicationForCompanyChange) .Select(x => x.Document) .ToList(); if (!documents.Any(x => x.Id == companyCase.DocumentId)) { var document = repo.AllReadonly <Document>() .Where(x => x.Id == companyCase.DocumentId) .Where(x => x.DocumentTypeId == NomenclatureConstants.DocumentType.ApplicationForCompanyRegister || x.DocumentTypeId == NomenclatureConstants.DocumentType.ApplicationForCompanyChange) .FirstOrDefault(); if (document != null) { documents.Add(document); } } foreach (var aDocument in documents) { int deadlineTypeId = 0; if (aDocument.DocumentTypeId == NomenclatureConstants.DocumentType.ApplicationForCompanyRegister) { deadlineTypeId = NomenclatureConstants.DeadlineType.CompanyCaseRegister; } if (aDocument.DocumentTypeId == NomenclatureConstants.DocumentType.ApplicationForCompanyChange) { deadlineTypeId = NomenclatureConstants.DeadlineType.CompanyCaseChange; } if (deadlineTypeId == 0) { continue; } var deadline = repo.AllReadonly <CaseDeadline>() .Where(x => x.SourceType == SourceTypeSelectVM.Document && x.SourceId == aDocument.Id && (x.DeadlineTypeId == deadlineTypeId)) .FirstOrDefault(); var deadlineType = repo.AllReadonly <DeadlineType>().Where(x => x.Id == deadlineTypeId).FirstOrDefault(); bool isSet = false; if (deadline != null) { if (deadline.StartDate != aDocument.DocumentDate.Date) { deadline.StartDate = aDocument.DocumentDate.Date; setDateEnd(deadline, deadlineType); isSet = true; } } else { deadline = new CaseDeadline(); deadline.CaseId = companyCase.Id; deadline.SourceType = SourceTypeSelectVM.Document; deadline.SourceId = aDocument.Id; deadline.DeadlineTypeId = deadlineTypeId; deadline.DeadlineGroupId = deadlineType.DeadlineGroupId; deadline.StartDate = aDocument.DocumentDate.Date; setDateEnd(deadline, deadlineType); isSet = true; } if (deadline != null && isSet) { result.Add(deadline); } } return(result); }
public CaseDeadline DeadLineOpenSessionResultStart(CaseSession session) { var aSessionType = session.SessionType; if (aSessionType == null) { aSessionType = repo.AllReadonly <SessionType>() .Where(x => x.Id == session.SessionTypeId) .FirstOrDefault(); } if (aSessionType == null) { return(null); } if (aSessionType.SessionTypeGroup == NomenclatureConstants.CaseSessionTypeGroup.PrivateSession) { return(null); } if (session.SessionStateId != NomenclatureConstants.SessionState.Provedeno) { return(null); } var deadline = repo.AllReadonly <CaseDeadline>() .Where(x => x.SourceType == SourceTypeSelectVM.CaseSession && x.SourceId == session.Id && x.DeadlineTypeId == NomenclatureConstants.DeadlineType.OpenSessionResult) .FirstOrDefault(); if (session.DateExpired != null) { if (deadline != null && deadline.DateExpired == null) { setExpired(deadline); return(deadline); } return(null); } var aCase = session.Case; if (aCase == null) { aCase = repo.AllReadonly <Case>().Where(x => x.Id == session.CaseId).FirstOrDefault(); } var deadlineType = repo.AllReadonly <DeadlineType>().Where(x => x.Id == NomenclatureConstants.DeadlineType.OpenSessionResult).FirstOrDefault(); var sessionMeeting = repo.AllReadonly <CaseSessionMeeting>() .Where(x => x.CaseSessionId == session.Id) .OrderBy(x => x.DateTo) .LastOrDefault(); var startDate = (sessionMeeting?.DateTo ?? session.DateTo) ?? DateTime.Now; startDate = startDate.AddDays(1); if (deadline != null) { if (deadline.StartDate.Date != startDate.Date || deadline.DateExpired != null) { setUnExpired(deadline); deadline.StartDate = startDate; setDateEnd(deadline, deadlineType); } else { return(null); } } else { deadline = new CaseDeadline(); deadline.CaseId = aCase.Id; deadline.SourceType = SourceTypeSelectVM.CaseSession; deadline.SourceId = session.Id; deadline.DeadlineTypeId = NomenclatureConstants.DeadlineType.OpenSessionResult; deadline.DeadlineGroupId = deadlineType.DeadlineGroupId; deadline.StartDate = startDate; setDateEnd(deadline, deadlineType); } return(deadline); }
public CaseDeadline DeadLineDeclaredForResolveStart(CaseSessionResult sessionResult) { CaseSession session = repo.AllReadonly <CaseSession>().Where(x => x.Id == sessionResult.CaseSessionId).FirstOrDefault(); if (session == null) { return(null); } var deadline = repo.AllReadonly <CaseDeadline>() .Where(x => x.SourceType == SourceTypeSelectVM.CaseSession && x.SourceId == session.Id && x.CaseSessionResultId == sessionResult.Id && x.DeadlineTypeId == NomenclatureConstants.DeadlineType.DeclaredForResolve) .FirstOrDefault(); var aCase = session.Case; if (aCase == null) { aCase = repo.AllReadonly <Case>().Where(x => x.Id == session.CaseId).FirstOrDefault(); } var deadlineType = repo.AllReadonly <DeadlineType>().Where(x => x.Id == NomenclatureConstants.DeadlineType.DeclaredForResolve).FirstOrDefault(); bool isSet = false; if (deadline != null) { if (sessionResult.SessionResultId == NomenclatureConstants.CaseSessionResult.AnnouncedForResolution || sessionResult.DateExpired != null) { if (deadline.DateExpired != null) { setUnExpired(deadline); isSet = true; } if (deadline.StartDate != session.DateTo && session.DateTo != null) { deadline.StartDate = session.DateTo ?? deadline.StartDate; setDateEnd(deadline, deadlineType); isSet = true; } } else { setExpired(deadline); isSet = true; } } else { if (sessionResult.SessionResultId == NomenclatureConstants.CaseSessionResult.AnnouncedForResolution) { deadline = new CaseDeadline(); deadline.CaseId = session.CaseId; deadline.SourceType = SourceTypeSelectVM.CaseSession; deadline.SourceId = session.Id; deadline.DeadlineTypeId = NomenclatureConstants.DeadlineType.DeclaredForResolve; deadline.DeadlineGroupId = deadlineType.DeadlineGroupId; deadline.CaseSessionResultId = sessionResult.Id; deadline.StartDate = session.DateTo ?? DateTime.Now; setDateEnd(deadline, deadlineType); isSet = true; } } if (deadline != null && isSet) { return(deadline); } else { return(null); } }
private void setExpired(CaseDeadline deadline) { deadline.DateExpired = DateTime.Now; deadline.UserExpiredId = userContext.UserId; deadline.DescriptionExpired = ""; }
private bool SaveDeadLine(CaseDeadline deadline) { if (deadline != null) { if (workNotificationService.GetJudgeUserId(deadline.CaseId) == null) { return(false); } deadline.UserId = userContext.UserId; deadline.DateWrt = DateTime.Now; if ((deadline.CourtId ?? 0) <= 0) { deadline.CourtId = userContext.CourtId; } if (deadline.DateComplete == null && deadline.DateExpired == null) { var workNotification = workNotificationService.NewWorkNotification(deadline); if (workNotification != null) { workNotification.CaseDeadline = deadline; if (workNotification.Id == 0) { repo.Add(workNotification); } else { repo.Update(workNotification); } } else { if (deadline.Id == 0) { repo.Add(deadline); } else { repo.Update(deadline); } } return(true); } if (deadline.DateComplete != null || deadline.DateExpired != null) { if (deadline.Id == 0) { repo.Add(deadline); } else { repo.Update(deadline); } var workNotifications = repo.AllReadonly <WorkNotification>() .Where(x => x.CaseDeadlineId == deadline.Id && x.DateExpired == null) .ToList(); foreach (var workNotification in workNotifications) { workNotification.DateExpired = deadline.DateExpired ?? deadline.DateComplete; workNotification.DescriptionExpired = deadline.DescriptionExpired; workNotification.UserExpiredId = deadline.UserExpiredId ?? deadline.UserId; repo.Update(workNotification); } } } return(false); }