using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; using BeWoPlanerMobil.Service; using BS.Shared; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; namespace BeWoPlanerMobil.Models { public class MainModel { [Display(Name = "Nur meine Hilfepläne anzeigen")] public bool ShowOnlyOwnSupportConcepts { get; set; } [Display(Name = "Abgelaufene Hilfepläne anzeigen")] public bool ShowExpiredSupportConcepts { get; set; } [Display(Name = "Hilfeplan")] public long? CostBearer2SupportConceptOid { get; set; } [Display(Name = "Kategorie")] public long? SelectedServiceCategoryConceptOid { get; set; } public long? SelectedServiceDescriptionOid { get; set; } public long? SelectedServiceRecordOid { get; set; } public ServiceRecordDC SelectedServiceRecord { get; set; } public SupportConceptDC SelectedSupportConcept { get; set; } public int Zeitraum { get; set; } public bool SaveSignature { get; set; } public int ErrorWert { get; set; } public bool ShowSignature { get; set; } public long ServiceRecordOid { get; set; } public List SupportConcepts { get; set; } public List ServiceCategories { get; set; } public List Textbausteine { get; set; } private List _ServiceRecords; public List ServiceRecords { get { if(_ServiceRecords == null) { return _ServiceRecords = new List(); } return _ServiceRecords.OrderByDescending(sr => sr.Start).ToList(); } set => _ServiceRecords = value; } public List SelectedGoals { get; set; } public ServiceRecordDC NewServiceRecord { get; set; } public long? ServiceRecordOidToDelete { get; set; } public static bool IsEditBtnVisible { get { return MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Edit))); } } public static bool IsDeleteBtnVisible { get { return MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Delete))); } } public static bool IsAllowedToCreateOrEditRecord { get { return MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Create))) || MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Edit))); } } public static bool IsOnlyAllowedToEdit { get { return !MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Create))) && MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Edit))); } } public static bool IsAllowedToSeeCustomers => MobileSessionFacade.CheckForUserRight(UserRightType.CustomerView_View) || MobileSessionFacade.CheckForUserRight(UserRightType.Customer_ViewMyCustomers); public static bool IsEmployeeSelectionVisible => MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherEmployees) || MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherTeamMember); public static bool IsTextbausteineVisible => MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen) || MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen); //public static bool IsTextbausteineVisible = false; public bool ShowDistanceField { get; set; } public MainModel() { NewServiceRecord = new ServiceRecordDC(); ShowOnlyOwnSupportConcepts = true; Zeitraum = -1; ErrorWert = 1; } public IEnumerable SupportConceptListItems { get { var allCostBearerRelations = new List { new SelectListItem { Selected = true, Value = "-1", Text = string.Empty }, new SelectListItem {Value = "-2", Text = "Ohne Hilfeplan"} }; foreach (var sc in SupportConcepts.OrderBy(sc => sc.Customer.LastName)) { allCostBearerRelations.AddRange(sc.CostBearerRelations.Where(w => ShowExpiredSupportConcepts || w.EndDate == null || w.EndDate.Value >= DateTime.Now).Select(cb => new SelectListItem { Value = cb.CostBearer2SupportConceptOid.ToString(), Text = $"{sc.Customer.LastNameFirstName} | {cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}" })); } return allCostBearerRelations; } } public IEnumerable SupporConceptListItemsForGroupBooking { get { var allCostBearerRelations = new List(); foreach(var sc in SupportConcepts.OrderBy(sc => sc.Customer.LastName)) { allCostBearerRelations.AddRange(sc.CostBearerRelations.Where(w => ShowExpiredSupportConcepts || w.EndDate == null || w.EndDate.Value >= DateTime.Now).Select(cb => new SelectListItem { Value = cb.CostBearer2SupportConceptOid.ToString(), Text = $"{sc.Customer.LastNameFirstName} | {cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}" })); } return allCostBearerRelations; } } public IEnumerable ServiceCategoryListItems { get { var result = new List(); result.AddRange(ServiceCategories.Select(item => new SelectListItem {Value = item.ServiceCategoryOid.Value.ToString(), Text = item.Name}).ToList()); return result; } } public IEnumerable GroupOfPeopleListItems { get { var result = new List(); foreach(var group in GroupsOfPeople) { result.Add(new SelectListItem { Value = $"{group.GroupOfPeopleOid.Value}", Text = group.Name }); } return result; } } public List Customers { get; set; } public List Employees { get; set; } public EmployeeDC Employee { get; set; } [Display(Name = "Klient")] public long? SelectedCustomerOid { get; set; } public CustomerDC SelectedCustomer { get; set; } public IEnumerable CustomerListItems { get { var result = new List {new SelectListItem {Value = "-1", Text = string.Empty}}; result.AddRange(Customers.Select(item => new SelectListItem { Value = item.CustomerOid.ToString(), Text = string.Format("{1}, {0}", item.FirstName, item.LastName) }).ToList()); return result; } } public static List AllEmployees { get; set; } [Display(Name = "Mitarbeiter")] public long? SelectedEmployeeOid => SelectedEmployee?.EmployeeOid; public CompactEmployeeDC SelectedEmployee { get; set; } public List GroupsOfPeople { get; set; } = new List(); public List SelectedGroupOfPeopleOids { get; set; } = new List(); public IEnumerable EmployeeListItems { get { var result = new List(); result.AddRange(Employees.Select(item => new SelectListItem {Value = item.EmployeeOid.ToString(), Text = $"{item.LastName}, {item.FirstName}", Selected = item.Equals(MobileSessionFacade.LoggedInCompactEmployee)}).OrderBy(s => s.Text).ToList()); return result; } } public ValueListEntryDC[] Dokutypes { get; set; } public static DateTime? GetEndDateOfSupportConcept(SupportConceptDC pSupportConcept) { DateTime? maxDate = null; foreach(var relation in pSupportConcept.CostBearerRelations) { var end = relation.ApprovedEndDate ?? relation.RequestedEndDate; if(maxDate == null || end != null && end.Value > maxDate.Value) { maxDate = end; } } return maxDate; } public List SelectedSupportConcepts { get; set; } = new List(); public List SelectedCostbearerRelOids { get; set; } = new List(); public List SelectedEmployees { get; set; } = new List(); [Display(Name = "Gruppenbuchung")] public bool IsInGroupBookingMode { get => _IsInGroupBookingMode; //get => false; set { _IsInGroupBookingMode = value; if(!_IsInGroupBookingMode) { SelectedSupportConcepts?.Clear(); SelectedEmployees?.Clear(); } } } private bool _IsInGroupBookingMode; public bool IsInEditingMode { get; set; } public List GetServiceDesctiptions() { var result = new List(); foreach(var serviceCategoryModel in ServiceCategories) { foreach(var serviceDescription in serviceCategoryModel.ServiceDescriptions) { result.AddIfNotIn(serviceDescription); } } return result; } public bool IsServiceRecordNoticeMandatory { get; set; } = true; } }