using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Web.Mvc; using BeWoPlanerMobil.Models; using BeWoPlanerMobil.Service; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using Newtonsoft.Json; using DevExpress.XtraScheduler; using DevExpress.XtraScheduler.Compatibility; namespace BeWoPlanerMobil.Controllers { public class MainController : AbstractBaseController { private MainModel _Model; public MainModel Model { get { if (!MobileSessionFacade.IsUserLoggedIn()) { RedirectToActionPermanent("Index", "Login"); return null; } if (((MainModel) Session[MainModelSessionKey])?.Employee == null) { _Model = new MainModel { Employee = MobileSessionFacade.LoggedInEmployee }; Session[MainModelSessionKey] = _Model; } else { _Model = (MainModel)Session[MainModelSessionKey]; } return _Model; } } private const string MainModelSessionKey = "MainModel"; private Dictionary _ParentGoals; private static readonly List _Zieltypen = new List { ValueListEntryType.SupportConceptGoalCategoryType, ValueListEntryType.SupportConceptIndividualGoalCategoryType }; private static readonly List _Massnahmentypen = new List { ValueListEntryType.SupportConceptGoalType, ValueListEntryType.SupportConceptIndividualGoalType }; [Authorize] public ActionResult Main() { try { ViewData["ValidationError"] = string.Empty; if (!MobileSessionFacade.IsUserLoggedIn()) { return RedirectToActionPermanent("Index", "Login"); } var unter = GetSettingValue("ShowSignature"); Model.ShowSignature = unter == "1"; var test = Model.SaveSignature; Model.SelectedGoals = null; Model.ShowDistanceField = "1" == GetSettingValue("ShowDistanceFields"); Model.Dokutypes = ValueListService.GetAllValueListEntrysByType(ValueListEntryType.DocumentType); if (Model.Dokutypes != null) { Model.Dokutypes = Model.Dokutypes.OrderBy(s => s.ValueListEntryOid).ToArray(); } if(MainModel.AllEmployees == null) { MainModel.AllEmployees = EmployeeService.GetAllActiveEmployeesCompact(); } var myRelatedCustomers = Model.Employee == null ? new List() : Model.Employee.RelatedCustomers; if (MobileSessionFacade.CheckForUserRight(UserRightType.CustomerView_View)) { Model.Customers = CustomerService.GetAllActiveCustomers().OrderBy(k => k.LastName).ToList(); } else if(MobileSessionFacade.CheckForUserRight(UserRightType.Customer_ViewMyCustomers)) { Model.Customers = CustomerService.GetActiveCustomersById(myRelatedCustomers.Select(c => c.Customer.CustomerOid).ToList()).OrderBy(k => k.LastName).ToList(); } else { Model.Customers = new List(); } if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherEmployees)) { Model.Employees = EmployeeService.GetAllActiveEmployeesCompact(); } else if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherTeamMember) && Model.Employee != null && Model.Employee.EmployeeOid != null) { Model.Employees = EmployeeService.GetAllTeamMember(MobileSessionFacade.LoggedInCompactEmployee); } else { Model.Employees = new List { MobileSessionFacade.LoggedInCompactEmployee }; } if(Model.ShowOnlyOwnSupportConcepts == false && MobileSessionFacade.CheckForUserRight(UserRightType.SupportConcept_ViewAllSupportConcepts)) { Model.SupportConcepts = CustomerService.GetAllActiveSupportConcepts(); } else { Model.SupportConcepts = CustomerService.GetAllActiveSupportConceptsByCustomers(Model.Customers.Select(c => c.CustomerOid != null ? c.CustomerOid.Value : 0)); } if (Model.ServiceCategories == null) { Model.ServiceCategories = new List(); } if (Model.CostBearer2SupportConceptOid != null) { LoadRecordsToModel(); } } catch (Exception e) { log.Error(e.Message, e); } return View(Model); } [HttpPost] [Authorize] public ActionResult SetShowOnlyOwnSupportConcepts(FormCollection collection) { Model.ShowOnlyOwnSupportConcepts = "true,false" == collection["ShowOnlyOwnSupportConcepts"]; return RedirectToActionPermanent("Main"); } [HttpPost] public new ActionResult Logout() { return base.Logout(); } [Authorize] public string LoadGoals(long pCostbearer2SupportConceptOid) { if (Model == null) { return "SessionTimeout"; } var sc = Model.SupportConcepts.FirstOrDefault(f => f.CostBearerRelations.Any(cbr => cbr.CostBearer2SupportConceptOid.HasValue && cbr.CostBearer2SupportConceptOid.Value.Equals(pCostbearer2SupportConceptOid))); if (sc == null) { return string.Empty; } Model.SelectedSupportConcept = sc; var selectedGoals = sc.Goals; var missingParents = selectedGoals.Where(w => w.ParentOid != null && false == selectedGoals.Any(a => a.ValueListEntryOid.Equals(w.ParentOid))).Select(s => s.ParentOid).ToList(); _ParentGoals = new Dictionary(); foreach (var oid in missingParents) { LoadMissingParents(oid.Value); } return SerializeObject(BuildGoalTree(selectedGoals.Union(_ParentGoals.Values).ToList())); } private static List BuildGoalTree(List goals) { var ziele = goals.Where(w => _Zieltypen.Contains(w.Type)).OrderBy(s => s.TypeDescription).ToList(); var massnahmen = goals.Where(w => _Massnahmentypen.Contains(w.Type)).OrderBy(s => s.TypeDescription).ToList(); var goalTree = new List(); var goalTreeDic = new Dictionary(); foreach(var ziel in ziele) { var treeItem = new GoalTreeItem {Children = new List(), Header = ziel.TypeDescription, ParentOid = ziel.ParentOid, ValueListEntryOid = ziel.ValueListEntryOid}; goalTreeDic.Add(ziel.ValueListEntryOid.Value, treeItem); if(ziel.ParentOid == null) { goalTree.Add(treeItem); } } foreach(var zielMitEltern in goalTreeDic.Values.Where(w => w.ParentOid != null)) { goalTreeDic[zielMitEltern.ParentOid.Value].Children.Add(zielMitEltern); } foreach(var ziel in massnahmen) { var kind = new GoalTreeItem {Children = new List(), Header = ziel.TypeDescription, IsLeaf = true, ValueListEntryOid = ziel.ValueListEntryOid}; if(ziel.ParentOid != null && goalTreeDic.ContainsKey(ziel.ParentOid.Value)) { kind.ParentOid = goalTreeDic[ziel.ParentOid.Value].ParentOid; goalTreeDic[ziel.ParentOid.Value].Children.Add(kind); } } foreach(var item in goalTreeDic.Values) { if(item.Children.Count == 0 && item.ParentOid.HasValue) { item.IsLeaf = true; } } return goalTree; } private void LoadMissingParents(long pParentOid) { while(true) { var parentDC = ValueListService.GetValueListEntryByOid(pParentOid); if(!_ParentGoals.ContainsKey(parentDC.ValueListEntryOid.Value)) { _ParentGoals.Add(parentDC.ValueListEntryOid.Value, parentDC); if(parentDC.ParentOid != null) { pParentOid = parentDC.ParentOid.Value; continue; } } break; } } public string LoadBWPSettings() { var m = OperationsService.GetMandator(); var time = GetSettingValue(m.Settings, "TimeUntilUILock"); return SerializeObject(time); } public string CheckEndDate() { var m = OperationsService.GetMandator(); var endtime = GetSettingValue(m.Settings, "IsEndDateVisible"); return SerializeObject(endtime); } public string CheckOnlyYearMonth() { var m = OperationsService.GetMandator(); var yearMonth = GetSettingValue(m.Settings, "IsOnlyYearMonthVisible"); return SerializeObject(yearMonth); } public string CheckIsZeiterfassDateNormal() { var m = OperationsService.GetMandator(); var normal = GetSettingValue(m.Settings, "IsZeiterfassDateNormal"); return SerializeObject(normal); } public string CheckIsZeiterfassungInStdMin() { var m = OperationsService.GetMandator(); var zeiterInStdMin = GetSettingValue(m.Settings, "IsZeiterfassungInStdMin"); return SerializeObject(zeiterInStdMin); } public string CheckDokuReiter() { return SerializeObject(Model.Dokutypes); } private string GetSettingValue(string key) { var man = OperationsService.GetMandator(); return GetSettingValue(man.Settings, key); } private static string GetSettingValue(string settings, string key) { if (!string.IsNullOrEmpty(settings)) { if (settings.IndexOf(";") == -1 && settings.IndexOf("=") == -1) { return settings; } var keyValuePairs = settings.Split(';'); return (from pair in keyValuePairs select pair.Split('=') into keyValuePair where keyValuePair.Length == 2 where keyValuePair[0] == key select keyValuePair[1]).FirstOrDefault(); } return null; } [Authorize] public string LoadAppointments(string newtoday) { try { if (Model == null) { return "SessionTimeout"; } var date = DateTime.ParseExact(newtoday, "dd.MM.yyyy", null); var appointments = KalenderService.LoadFilteredAppointments(true, Model.Employee.EmployeeOid.Value, date.Date, date.Date.AddDays(1), new List(), new List(), new List(), false, false, false, false, true).OrderBy(x => x.StartDate.Value.Hour).ToList(); var holySweetFlyingFuck = appointments.Where(w => w.StartDate.HasValue && w.EndDate.HasValue && ((date.InBetween(w.StartDate.Value, w.EndDate.Value, false) || date.CompareShortDates(w.StartDate.Value)) && w.RecurrenceInfo == null || w.RecurrenceInfo != null && w.Type == 3 && (date.InBetween(w.StartDate.Value, w.EndDate.Value, false) || date.CompareShortDates(w.StartDate.Value)))).ToList(); foreach(var appointment in appointments) { // TODO: Exceptions herausfiltern! // TODO: Ein Serientermin wird nicht richtig angezeigt if(appointment.RecurrenceInfo != null && appointment.Type == 1) { var recurrenceInfo = new RecurrenceInfo(); recurrenceInfo.FromXml(appointment.RecurrenceInfo); var occurrenceCalculator = OccurrenceCalculator.CreateInstance(recurrenceInfo); var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern); pattern.RecurrenceInfo.FromXml(appointment.RecurrenceInfo); pattern.Start = pattern.RecurrenceInfo.Start; pattern.End = pattern.RecurrenceInfo.End; var occurrences = occurrenceCalculator.CalcOccurrences(new TimeInterval(date, date.AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999)), pattern); if(occurrences.Count > 0) { foreach(var termin in occurrences) { if(!date.InBetween(termin.Start, termin.End, false)) { continue; } var duration = (appointment.EndDate.Value - appointment.StartDate.Value).TotalMinutes; holySweetFlyingFuck.Add(new SchedulerAppointmentDC { AllDay = appointment.AllDay, CustomerList = appointment.CustomerList, Description = appointment.Description, EmployeeList = appointment.EmployeeList, EndDate = termin.Start.AddMinutes(duration), FormerBookingSequenceOid = appointment.FormerBookingSequenceOid, IsPrivate = appointment.IsPrivate, LabelId = appointment.LabelId, Location = appointment.Location, Originator = appointment.Originator, RecurrenceInfo = termin.RecurrenceInfo.ToXml(), ReminderInfo = appointment.ReminderInfo, ResourceList = appointment.ResourceList, StartDate = termin.Start, Subject = appointment.Subject, Type = appointment.Type }); } } } } return SerializeObject(holySweetFlyingFuck); } catch (Exception e) { log.Error(e.Message, e); return SerializeObject("Fehler 510"); } } [Authorize] public string LoadStatistics(long oid) { try { if (Model == null) { return "SessionTimeout"; } var parents = OperationsService.CreateSupportConceptStatistics(oid,DateTime.Now); return SerializeObject(parents); } catch (Exception e) { log.Error(e.Message, e); return SerializeObject("Fehler 560"); } } [Authorize] public void UpdateAppointment(long oid, string betreff, string notice, string startZeit, string endZeit, string day, string endDate) { try { if (Model == null) { SerializeObject("SessionTimeout"); } var date = DateTime.Parse(day); var end = DateTime.Parse(endDate); var zeit = ConvertRecordTimesWithEndDate(startZeit, endZeit, date, end, 0); var b1 = KalenderService.GetSchedulerAppointmentByid(oid); b1.EndDate = zeit[1]; b1.StartDate = zeit[0]; b1.Subject = betreff; b1.Description = notice; KalenderService.UpdateSchedulerAppointments(new List{b1}); } catch (Exception e) { log.Error(e.Message, e); SerializeObject("Fehler 550: Internal Server Error"); } } [Authorize] public void InsertAppointment(string day, string startZeit, string endZeit, string betreff, string notice, string endDate) { try { if (Model == null) { SerializeObject("SessionTimeout"); } var date = DateTime.Parse(day); var end = DateTime.Parse(endDate); var zeit = ConvertRecordTimesWithEndDate(startZeit, endZeit, date, end, 0); var a1 = new List { new SchedulerAppointmentDC { EmployeeList = new List(), CustomerList = new List(), ResourceList = new List(), EndDate = zeit[1], StartDate = zeit[0], Subject = betreff, Description = notice, Originator = MobileSessionFacade.LoggedInCompactEmployee } }; KalenderService.InsertSchedulerAppointments(a1); } catch (Exception e) { log.Error(e.Message, e); SerializeObject("Fehler 520"); } } [Authorize] public string LoadBeWoTasks(string newtoday) { try { if (Model == null) { return "SessionTimeout"; } var date = DateTime.ParseExact(newtoday, "dd.MM.yyyy", null); var tasks = AnalysisService.GetTasksForEmployeeByDate(Model.Employee.EmployeeOid.Value, date); return SerializeObject(tasks); } catch (Exception e) { log.Error(e.Message, e); return SerializeObject("Fehler 530"); } } [Authorize] public void SaveUnterschrift(string breitengrad, string langengrad, string blob, string zeitstempel, long? ServiceRecord) { try { if (Model == null) { SerializeObject("SessionTimeout"); } var date = DateTime.Parse(zeitstempel); OperationsService.InsertSignature(new SignatureDC { DataBild = blob, Latitute = breitengrad, Longitute = langengrad, Zeitstempel = date, ServiceRecordOid = ServiceRecord }); } catch (Exception e) { log.Error(e.Message, e); SerializeObject("Fehler 540"); } } public void SetSaveSignature(bool save) { try { if (Model == null) { SerializeObject("SessionTimeout"); } else { Model.SaveSignature = save; } } catch (Exception e) { log.Error(e.Message, e); SerializeObject("Fehler 777: Fail Error Compilation"); } } public string LoadServiceCategories(long pServiceCategoryOid) { var scm = Model?.ServiceCategories.FirstOrDefault(s => s.ServiceCategoryOid.Value == pServiceCategoryOid); return SerializeObject(scm != null ? scm.ServiceDescriptions : new List()); } [Authorize] public string LoadTextbausteineForServiceCategory(long pServiceCategoryOid) { if (!MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen) && !MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen)) { return null; } var textbausteine = OperationsService.GetAllTextModules(); if(MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen)) { textbausteine = textbausteine.Where(w => w.Employee.EmployeeOid == Model.Employee.EmployeeOid).ToList(); } Model.Textbausteine = textbausteine.Where(w => w.ServiceCategory != null && w.ServiceCategory.ServiceCategoryOid == pServiceCategoryOid).ToList(); Model.Textbausteine.AddRangeIfElementsNotIn(Utils.GetParentTextModules(Model.Textbausteine)); var displayItems = Model.Textbausteine.Select(s => new TextbausteinDisplayItem(s.TextModuleOid.Value, s.Name, s.Parent?.TextModuleOid, s.IsParent, s.Text)).ToList(); foreach(var item in displayItems) { if(item.ParentOid != null) { var parent = displayItems.FirstOrDefault(f => f.Oid == item.ParentOid); parent?.Children.AddIfNotIn(item); } } displayItems = displayItems.Where(w => w.ParentOid == null).ToList(); return SerializeObject(displayItems); } public string LoadCompleteTextbausteinByOid(long pTextbausteinOid) { var abc = Model.Textbausteine.FirstOrDefault(f => f.TextModuleOid.Value == pTextbausteinOid); return abc.Text; } // Ajax-Aufruf zum anzeigen, ob beim Speichern ein Fehler aufgetreten ist. public void ErrorZeiterfassungAnzeigen(int errorwert) { try { if (Model == null) { SerializeObject("SessionTimeout"); } else { Model.ErrorWert = errorwert; } } catch (Exception e) { log.Error(e.Message, e); SerializeObject("Fehler 777: Fail Error Compilation"); } } [HttpPost] [Authorize] public ActionResult CreateServiceRecord(FormCollection collection) { try { if (Model == null) { return RedirectToActionPermanent("Index", "Login"); } string doku1; if (Model.Dokutypes != null && Model.Dokutypes.Length > 1) { doku1 = collection["Dokumentation"]; } else { doku1 = collection["Dokumentation6"]; } log.Info($"CreateServiceRecord: datum:{collection["Datum"]}; start:{collection["Start"]}; ende:{collection["Ende"]}; dauer:{collection["Dauer"]}; doku:{doku1}; aktion:{collection["versteckt"]}"); if (string.IsNullOrEmpty(collection["Datum"])) { return View("Main", Model); } var distanz = collection["Distanz"]; int? distanceInMeters = null; if(!string.IsNullOrEmpty(distanz)) { if(int.TryParse(distanz, out var parsedDistance)) { distanceInMeters = parsedDistance; } } var submitBtnVal = collection["versteckt"]; var selectedCostbearerSCRelOid = Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid; var datum = Convert.ToDateTime(collection["Datum"]); var enddatum = datum; var start = collection["Start"]; var ende = collection["Ende"]; var dauer = 0; if (datum > enddatum) { enddatum = datum; } if (!string.IsNullOrEmpty(collection["Dauer"])) { int.TryParse(collection["Dauer"], out dauer); } var doku2 = collection["Dokumentation2"]; var doku3 = collection["Dokumentation3"]; var doku4 = collection["Dokumentation4"]; var doku5 = collection["Dokumentation5"]; var zeitenFeld = new DateTime[2]; if (start == string.Empty && ende == string.Empty) { zeitenFeld[0] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1); if(enddatum == datum) { zeitenFeld[1] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1).AddMinutes(dauer); } else { zeitenFeld[1] = new DateTime(enddatum.Year, enddatum.Month, enddatum.Day, 0, 0, 1).AddMinutes(dauer); } } else { zeitenFeld = enddatum == datum ? ConvertRecordTimes(start, ende, datum, dauer) : ConvertRecordTimesWithEndDate(start, ende, datum, enddatum, dauer); } if (dauer == 0 || zeitenFeld[1] != zeitenFeld[0]) { dauer = (int) (zeitenFeld[1] - zeitenFeld[0]).TotalMinutes; } if (submitBtnVal.Equals("Speichern")) { var selectedRecordOid = Model.SelectedServiceRecordOid; Model.NewServiceRecord = OperationsService.GetServiceRecordById(selectedRecordOid.Value); } if (Model.NewServiceRecord == null) { return RedirectToActionPermanent("Main"); } Model.NewServiceRecord.Goals = Model.SelectedGoals; Model.NewServiceRecord.Start = zeitenFeld[0]; Model.NewServiceRecord.End = zeitenFeld[1]; Model.NewServiceRecord.DistanceInMeter = distanceInMeters; if (Model.Employee.EmployeeOid != null) { if (!submitBtnVal.Equals("Speichern")) { Model.NewServiceRecord.Employee = Model.SelectedEmployee ?? MobileSessionFacade.LoggedInCompactEmployee; } var sc = Model.SupportConcepts.FirstOrDefault(fod => fod.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(selectedCostbearerSCRelOid))); if (sc != null) { if (sc.SupportConceptOid != null) { Model.NewServiceRecord.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid); } Model.NewServiceRecord.Customer = sc.Customer; var cb2ScRel = sc.CostBearerRelations.First( f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(selectedCostbearerSCRelOid)); Model.NewServiceRecord.CostBearer = cb2ScRel.CostBearer; var intervall = Model.NewServiceRecord.CostBearer.ActualMinuteIntervall; if (intervall > 0) { Model.NewServiceRecord.RoundedDuration = dauer%intervall != 0 ? dauer + (intervall - dauer%intervall) : dauer; } else { Model.NewServiceRecord.RoundedDuration = dauer; } Model.NewServiceRecord.CostBearer2SupportConceptOid = selectedCostbearerSCRelOid; } else { Model.NewServiceRecord.RoundedDuration = dauer; } } Model.NewServiceRecord.Notice = doku1; Model.NewServiceRecord.Notice2 = doku2; Model.NewServiceRecord.Notice3 = doku3; Model.NewServiceRecord.Notice4 = doku4; Model.NewServiceRecord.Notice5 = doku5; var serviceDescOid = 0L; if (Model.SelectedServiceDescriptionOid.HasValue) { serviceDescOid = Model.SelectedServiceDescriptionOid.Value; } else if (!string.IsNullOrEmpty(collection["Leistungen"])) { serviceDescOid = Convert.ToInt64(collection["Leistungen"]); } if (serviceDescOid > 0) { Model.NewServiceRecord.ServiceDescription = OperationsService.GetServiceDescription(serviceDescOid); } if (Model.NewServiceRecord.RoundedDuration == 0) { Model.NewServiceRecord.RoundedDuration = dauer; } Model.NewServiceRecord.IP = Request.UserHostAddress; Model.NewServiceRecord.InsertedOn = DateTime.Now; Model.NewServiceRecord.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}"; Model.NewServiceRecord.IsCreatedInMobileClient = true; if (submitBtnVal.Equals("Anlegen")) { var oidList = OperationsService.InsertNewServiceRecords(new List { Model.NewServiceRecord }); Model.ServiceRecordOid = oidList[0]; } else { OperationsService.UpdateServiceRecords(new List { Model.NewServiceRecord }); } Model.NewServiceRecord = new ServiceRecordDC(); if (selectedCostbearerSCRelOid.HasValue) { Model.ServiceRecords = OperationsService.FindServiceRecordsForLastDays(selectedCostbearerSCRelOid, Model.Zeitraum, Model.Employee.EmployeeOid).ToList(); } } catch (Exception e) { log.Error(e.Message, e); } Model.SaveSignature = Model.ShowSignature; return RedirectToActionPermanent("Main"); } public ActionResult SaveZeiterfassungAfterCrash(string Datum, string StartD, string EndeD, string Dauer, string Doku, string Leistungen, string Doku2, string Doku3, string Doku4, string Doku5, string EndDatum) { try { if (Model == null) { return RedirectToActionPermanent("Index", "Login"); } log.Info($"saveZeiterfassungAfterCrash: datum:{Datum};start:{StartD};ende:{EndeD};dauer:{Dauer};doku:{Doku};doku2:{Doku2};doku3:{Doku3};doku4:{Doku4};doku5:{Doku5};EndDatum:{EndDatum}"); if (string.IsNullOrEmpty(Datum)) { return View("Main", Model); } var selectedCostbearerSCRelOid = Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid; var datum = Convert.ToDateTime(Datum); var start = StartD; var ende = EndeD; var dauer = 0; var enddatum = EndDatum != "" ? Convert.ToDateTime(EndDatum) : datum; if (datum > enddatum) { enddatum = datum; } if (!string.IsNullOrEmpty(Dauer)) { int.TryParse(Dauer, out dauer); } var doku = Doku; var doku2 = Doku2; var doku3 = Doku3; var doku4 = Doku4; var doku5 = Doku5; var zeitenFeld = new DateTime[2]; if (start == string.Empty && ende == string.Empty) { zeitenFeld[0] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1); if (enddatum == datum) { zeitenFeld[1] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1).AddMinutes(dauer); } else { zeitenFeld[1] = new DateTime(enddatum.Year, enddatum.Month, enddatum.Day, 0, 0, 1).AddMinutes(dauer); } } else { zeitenFeld = enddatum == datum ? ConvertRecordTimes(start, ende, datum, dauer) : ConvertRecordTimesWithEndDate(start, ende, datum, enddatum, dauer); } if (dauer == 0 || zeitenFeld[1] != zeitenFeld[0]) { dauer = (int)(zeitenFeld[1] - zeitenFeld[0]).TotalMinutes; } if (Model.NewServiceRecord == null) { return RedirectToActionPermanent("Main"); } Model.NewServiceRecord.Goals = Model.SelectedGoals; Model.NewServiceRecord.Start = zeitenFeld[0]; Model.NewServiceRecord.End = zeitenFeld[1]; if (Model.Employee.EmployeeOid != null) { Model.NewServiceRecord.Employee = Model.SelectedEmployee ?? MobileSessionFacade.LoggedInCompactEmployee; var sc = Model.SupportConcepts.FirstOrDefault(fod => fod.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(selectedCostbearerSCRelOid))); if (sc != null) { if (sc.SupportConceptOid != null) { Model.NewServiceRecord.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid); } Model.NewServiceRecord.Customer = sc.Customer; var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(selectedCostbearerSCRelOid)); Model.NewServiceRecord.CostBearer = cb2ScRel.CostBearer; var intervall = Model.NewServiceRecord.CostBearer.ActualMinuteIntervall; if (intervall > 0) { Model.NewServiceRecord.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - dauer % intervall) : dauer; } else { Model.NewServiceRecord.RoundedDuration = dauer; } Model.NewServiceRecord.CostBearer2SupportConceptOid = selectedCostbearerSCRelOid; } else { Model.NewServiceRecord.RoundedDuration = dauer; } } Model.NewServiceRecord.Notice = doku; if (doku2 != "") { Model.NewServiceRecord.Notice2 = doku2; } if (doku3 != "") { Model.NewServiceRecord.Notice3 = doku3; } if (doku4 != "") { Model.NewServiceRecord.Notice4 = doku4; } if (doku5 != "") { Model.NewServiceRecord.Notice5 = doku5; } var serviceDescOid = 0L; if (Model.SelectedServiceDescriptionOid.HasValue) { serviceDescOid = Model.SelectedServiceDescriptionOid.Value; } else if (!string.IsNullOrEmpty(Leistungen)) { serviceDescOid = Convert.ToInt64(Leistungen); } if (serviceDescOid > 0) { Model.NewServiceRecord.ServiceDescription = OperationsService.GetServiceDescription(serviceDescOid); } Model.NewServiceRecord.IP = Request.UserHostAddress; Model.NewServiceRecord.InsertedOn = DateTime.Now; Model.NewServiceRecord.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}"; Model.NewServiceRecord.IsCreatedInMobileClient = true; OperationsService.InsertNewServiceRecords(new List { Model.NewServiceRecord }); Model.NewServiceRecord = new ServiceRecordDC(); if (selectedCostbearerSCRelOid.HasValue) { Model.ServiceRecords = OperationsService.FindServiceRecordsForLastDays(selectedCostbearerSCRelOid, Model.Zeitraum, Model.Employee.EmployeeOid).ToList(); } } catch (Exception e) { log.Error(e.Message, e); Model.ErrorWert = 2; //log.Error(e.Message, e); } return RedirectToActionPermanent("Main"); } [HttpPost] [Authorize] public ActionResult SelectSupportConcept(FormCollection formCollection) { if (Model == null) { return RedirectToActionPermanent("Index", "Login"); } long? cb2scOid = Convert.ToInt64(formCollection["CostBearer2SupportConceptOid"]); Model.CostBearer2SupportConceptOid = cb2scOid; Model.SelectedSupportConcept = Model.SupportConcepts.FirstOrDefault( f => f.CostBearerRelations.Any( a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(Model.CostBearer2SupportConceptOid))); if (Model.SelectedSupportConcept != null) { var details = OperationsService.GetSupportConceptTreeNodeDetailInfo(Model.SelectedSupportConcept.Customer.CustomerOid, Model.SelectedSupportConcept.SupportConceptOid, Model.CostBearer2SupportConceptOid); Model.ServiceCategories = details.ServiceAccountings.Count > 0 ? CreateServiceCategoryModels(details.ServiceAccountings.Select(sa => sa.ServiceDescription).ToList()) //if : CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions()); //else Model.ServiceCategories = Model.ServiceCategories.Where(c => !c.OhneHilfeplan.HasValue || c.OhneHilfeplan.Value == AccountingvisibilityType.Beides || c.OhneHilfeplan.Value == AccountingvisibilityType.NurKlientenbezogen).ToList(); } else if (cb2scOid == -2) { Model.ServiceCategories = CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions()); Model.ServiceCategories = Model.ServiceCategories.Where(c => !c.OhneHilfeplan.HasValue || c.OhneHilfeplan.Value == AccountingvisibilityType.Beides || c.OhneHilfeplan.Value == AccountingvisibilityType.NichtKlientenbezogen).ToList(); } else if (cb2scOid == -1) { Model.ServiceCategories.Clear(); } Model.Zeitraum = 7; LoadRecordsToModel(); return RedirectToActionPermanent("Main"); } private static List CreateServiceCategoryModels(IEnumerable serviceDescriptions) { var catOid2ModelDict = new Dictionary(); foreach (var sd in serviceDescriptions) { if (!catOid2ModelDict.ContainsKey(sd.Category.ServiceCategoryOid.Value)) { catOid2ModelDict[sd.Category.ServiceCategoryOid.Value] = new ServiceCategoryModel() { Name = sd.Category.Name, IsDefault = sd.Category.IsDefault, Percentage = sd.Category.Percentage, Position = sd.Category.Position, OhneHilfeplan = sd.Category.OhneHilfeplan, ServiceCategoryOid = sd.Category.ServiceCategoryOid, ServiceDescriptions = new List() }; } catOid2ModelDict[sd.Category.ServiceCategoryOid.Value].ServiceDescriptions.Add(sd); } var list = catOid2ModelDict.Values.ToList(); list.Sort((s1, s2) => { if (s1.IsDefault) { return 1; } return s1.Position != s2.Position ? s1.Position.CompareTo(s2.Position) : s1.ServiceCategoryOid.Value.CompareTo(s2.ServiceCategoryOid.Value); }); return list; } [HttpPost] [Authorize] public ActionResult DeleteServiceRecord() { if (Model == null) { return RedirectToActionPermanent("Index", "Login"); } if (Model.ServiceRecordOidToDelete != null && Model.ServiceRecordOidToDelete > 0 && MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Delete)))) { var serviceRecordDC = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid != null && f.ServiceRecordOid.Value.Equals(Model.ServiceRecordOidToDelete)); var version = serviceRecordDC?.ServiceRecordVersion; if (version != null) { OperationsService.DeleteServiceRecord(Model.ServiceRecordOidToDelete.Value, version.Value); Model.ServiceRecords = Model.ServiceRecords.Where(sr => sr.ServiceRecordOid != null && !sr.ServiceRecordOid.Value.Equals(serviceRecordDC.ServiceRecordOid)).ToList(); } } return RedirectToActionPermanent("Main", Model); } public void SetRecordOidToDelete(long serviceRecordOid) { if (Model == null) { RedirectToActionPermanent("Index", "Login"); return; } Model.ServiceRecordOidToDelete = serviceRecordOid; } public void UpdateGoals(long pGoalOid) { if (Model == null) { RedirectToActionPermanent("Index", "Login"); return; } var sc = Model.SelectedSupportConcept; if (sc == null) { return; } var goal = sc.Goals.FirstOrDefault(first => first.ValueListEntryOid.HasValue && first.ValueListEntryOid.Value.Equals(pGoalOid)); if (Model.SelectedGoals == null) { Model.SelectedGoals = new List { goal }; return; } if (Model.SelectedGoals.Contains(goal)) { Model.SelectedGoals.Remove(goal); } else { Model.SelectedGoals.Add(goal); } } public class GoalTreeItem { public string Header { get; set; } public bool IsLeaf { get; set; } public List Children { get; set; } public long? ParentOid { get; set; } public long? ValueListEntryOid { get; set; } } public void SetServiceDescription(long pServiceDescriptionOid) { if (Model == null) { RedirectToActionPermanent("Index", "Login"); return; } Model.SelectedServiceDescriptionOid = pServiceDescriptionOid; } [HttpPost] [Authorize] public ActionResult LoadServiceRecords(FormCollection formCollection) { if (Model == null) { return RedirectToActionPermanent("Index", "Login"); } var zeitraum = int.Parse(formCollection["Records"]); if (zeitraum < 0) { zeitraum = 7; } Model.Zeitraum = zeitraum; LoadRecordsToModel(); return RedirectToActionPermanent("Main"); } private void LoadRecordsToModel() { if(Model.Zeitraum < 0 || Model.CostBearer2SupportConceptOid.HasValue && Model.CostBearer2SupportConceptOid.Value == -1) { Model.ServiceRecords = new List(); return; } var records = OperationsService.FindServiceRecordsForLastDays(Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid, Model.Zeitraum, Model.Employee.EmployeeOid); var recordsOhneDuplikate = new List(); foreach(var r in records.Where(r => !recordsOhneDuplikate.Any(a => a.GroupOid.HasValue && a.GroupOid.Value.Equals(r.GroupOid)))) { recordsOhneDuplikate.Add(r); } Model.ServiceRecords = recordsOhneDuplikate; } public void SetSelectedServiceRecord(long? recordOid) { if (Model == null) { RedirectToActionPermanent("Index", "Login"); return; } Model.SelectedServiceRecordOid = recordOid; if (recordOid == null) { Model.SelectedGoals = new List(); } else { var serviceRecordDC = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid.HasValue && f.ServiceRecordOid.Value.Equals(Model.SelectedServiceRecordOid)); if (serviceRecordDC != null) { Model.SelectedGoals = serviceRecordDC.Goals; } } } public string GetSelectedRecordInformation() { var result = string.Empty; if (Model.SelectedServiceRecordOid.HasValue) { result = SerializeObject(Model.ServiceRecords.First(f => f.ServiceRecordOid == Model.SelectedServiceRecordOid)); } return result; } public string GetSelectedRecordInformationWithOid(long oid) { LoadRecordsToModel(); return SerializeObject(Model.ServiceRecords.First(f => f.ServiceRecordOid == oid)); } private static string SerializeObject(object obj) { return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); } private static DateTime[] ConvertRecordTimes(string start, string ende, DateTime datum, int dauer) { var result = new DateTime[2]; var startDate = datum.Date; var endDate = datum.Date; var dateTemp = ConvertTimeStringToDateTime(start); startDate = startDate.AddHours(dateTemp.Hour).AddMinutes(dateTemp.Minute); dateTemp = ConvertTimeStringToDateTime(ende); endDate = endDate.AddHours(dateTemp.Hour).AddMinutes(dateTemp.Minute); if (string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(ende)) { startDate = endDate.AddMinutes(-1 * dauer); } if (string.IsNullOrEmpty(ende) && !string.IsNullOrEmpty(start)) { endDate = startDate.AddMinutes(dauer); } if (endDate < startDate) { endDate = startDate; } result[0] = startDate; result[1] = endDate; return result; } private static DateTime[] ConvertRecordTimesWithEndDate(string start, string ende, DateTime datum, DateTime enddatum, int dauer) { var result = new DateTime[2]; var startDate = datum; var endDate = enddatum; var h = 0; var m = 0; if (!string.IsNullOrEmpty(start) && (start.Contains(":") || start.Contains(".") || start.Contains(","))) { var seperator = ':'; if (start.Contains(".")) { seperator = '.'; } else if (start.Contains(",")) { seperator = ','; } var hm = start.Split(seperator); h = Convert.ToInt32(hm[0]); m = Convert.ToInt32(hm[1]); } else if (!string.IsNullOrEmpty(start)) { m = Convert.ToInt32(start.Substring(start.Length - 2, 2)); h = Convert.ToInt32(start.Substring(0, start.Length - 2)); } startDate = startDate.AddHours(h); startDate = startDate.AddMinutes(m); if (!string.IsNullOrEmpty(ende) && (ende.Contains(":") || ende.Contains(".") || ende.Contains(","))) { var seperator2 = ':'; if (ende.Contains(".")) { seperator2 = '.'; } else if (ende.Contains(",")) { seperator2 = ','; } var hm = ende.Split(seperator2); h = Convert.ToInt32(hm[0]); m = Convert.ToInt32(hm[1]); } else if (!string.IsNullOrEmpty(ende)) { m = Convert.ToInt32(ende.Substring(ende.Length - 2, 2)); h = Convert.ToInt32(ende.Substring(0, ende.Length - 2)); } endDate = endDate.AddHours(h); endDate = endDate.AddMinutes(m); if (string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(ende)) { startDate = endDate.AddMinutes(-1 * dauer); } if (string.IsNullOrEmpty(ende) && !string.IsNullOrEmpty(start)) { endDate = startDate.AddMinutes(dauer); } if (endDate < startDate) { endDate = startDate; } if (dauer == 0 || endDate == startDate) { dauer = (int)(endDate - startDate).TotalMinutes; } result[0] = startDate; result[1] = endDate; return result; } public string CheckRights(string von, string bis, bool inEditMode, string dateString, string startString, string endString) { if (Model == null) { return "SessionTimeout"; } log.Info($"CheckRights: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}"); var startHoursDt = ConvertTimeStringToDateTime(startString); var endHoursDt = ConvertTimeStringToDateTime(endString); if (!DateTime.TryParse(dateString, out var date)) { date = DateTime.Now.Date; } var startDt = date.AddHours(startHoursDt.Hour).AddMinutes(startHoursDt.Minute); var endDt = date.AddHours(endHoursDt.Hour).AddMinutes(endHoursDt.Minute); if (startDt > endDt) { return "StartGreaterEnd"; } var dauer = (int)(endDt - startDt).TotalMinutes; if (dauer == 0) { startDt = startDt.AddSeconds(1); endDt = endDt.AddSeconds(1); } var checkSR = new ServiceRecordDC(); if (inEditMode) { checkSR = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid.HasValue && f.ServiceRecordOid.Value.Equals(Model.SelectedServiceRecordOid)); } if (checkSR == null) { checkSR = new ServiceRecordDC(); } checkSR.Goals = Model.SelectedGoals; checkSR.Start = startDt; checkSR.End = endDt; if (Model.Employee.EmployeeOid != null) { checkSR.Employee = MobileSessionFacade.LoggedInCompactEmployee; var sc = Model.SupportConcepts.FirstOrDefault(fod => fod.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(Model.CostBearer2SupportConceptOid))); if (sc != null) { if (sc.SupportConceptOid != null) { checkSR.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid); } checkSR.Customer = sc.Customer; var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(Model.CostBearer2SupportConceptOid)); checkSR.CostBearer = cb2ScRel.CostBearer; var intervall = checkSR.CostBearer.ActualMinuteIntervall; if (intervall > 0) { checkSR.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - (dauer % intervall)) : dauer; } checkSR.CostBearer2SupportConceptOid = Model.CostBearer2SupportConceptOid; } } checkSR.IP = Request.UserHostAddress; checkSR.InsertedOn = DateTime.Now; checkSR.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}"; checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value); var man = OperationsService.GetMandator(); var s = man.Settings ?? string.Empty; var einzeln = s.Split(';'); var g = einzeln.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed")); var t = g != null ? int.Parse(g.Split('=')[1]) : 0; SupportConceptStatisticsDC stats = null; if (Model.CostBearer2SupportConceptOid != null && Model.CostBearer2SupportConceptOid > 0) { stats = OperationsService.CreateSupportConceptStatistics(Model.CostBearer2SupportConceptOid.Value, DateTime.Now); } var result = OperationsService.ValidateServiceRecordEntry(checkSR, stats, t, false, new List { checkSR.Employee.EmployeeOid }); var valStruct = new ValidationStruct { ValidationResults = result, Rights = new Dictionary(), MaxDaysEditServiceRecordsAllowed = t.ToString() }; valStruct.Rights.Add(0, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecord_AllowCreateOverlappingFLS)))); valStruct.Rights.Add(1, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecord_AllowCreateMoreFLSThanApproved)))); valStruct.Rights.Add(2, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.BookServiceRecordAfterSettlementInvoice)))); Model.NewServiceRecord = new ServiceRecordDC(); return SerializeObject(valStruct); } public bool CheckRightsAfterCrash(string von, string bis, bool inEditMode, string dateString, string startString, string endString, long costbearerOId, string leistung) { if (Model == null) { return false; } log.Info($"CheckRightsAfterCrash: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}"); var date = DateTime.Now.Date; var startHoursDt = ConvertTimeStringToDateTime(startString); var endHoursDt = ConvertTimeStringToDateTime(endString); if (!DateTime.TryParse(dateString, out date)) { date = DateTime.Now.Date; } var startDt = date.AddHours(startHoursDt.Hour).AddMinutes(startHoursDt.Minute); var endDt = date.AddHours(endHoursDt.Hour).AddMinutes(endHoursDt.Minute); if (startDt > endDt) { Model.ErrorWert = 5; return false; } var dauer = (int)(endDt - startDt).TotalMinutes; if (dauer == 0) { startDt = startDt.AddSeconds(1); endDt = endDt.AddSeconds(1); } var checkSR = new ServiceRecordDC { Goals = Model.SelectedGoals, Start = startDt, End = endDt }; if (Model.Employee.EmployeeOid != null) { checkSR.Employee = MobileSessionFacade.LoggedInCompactEmployee; _Model.CostBearer2SupportConceptOid = costbearerOId; var sc = Model.SupportConcepts.FirstOrDefault(fod => fod.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(Model.CostBearer2SupportConceptOid))); if (sc != null) { if (sc.SupportConceptOid != null) { checkSR.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid); } checkSR.Customer = sc.Customer; var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(Model.CostBearer2SupportConceptOid)); checkSR.CostBearer = cb2ScRel.CostBearer; var intervall = checkSR.CostBearer.ActualMinuteIntervall; if (intervall > 0) { checkSR.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - (dauer % intervall)) : dauer; } checkSR.CostBearer2SupportConceptOid = Model.CostBearer2SupportConceptOid; } } checkSR.IP = Request.UserHostAddress; checkSR.InsertedOn = DateTime.Now; checkSR.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}"; if (leistung != null || leistung == "") { Model.SelectedServiceDescriptionOid = Convert.ToInt64(leistung); } else { Model.SelectedServiceDescriptionOid = 6; } checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value); var man = OperationsService.GetMandator(); var s = man.Settings ?? string.Empty; var einzeln = s.Split(';'); var g = einzeln.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed")); var t = g != null ? int.Parse(g.Split('=')[1]) : 0; SupportConceptStatisticsDC stats = null; if (Model.CostBearer2SupportConceptOid != null && Model.CostBearer2SupportConceptOid > 0) { stats = OperationsService.CreateSupportConceptStatistics(Model.CostBearer2SupportConceptOid.Value, DateTime.Now); } var result = OperationsService.ValidateServiceRecordEntry(checkSR, stats, t, false, new List { checkSR.Employee.EmployeeOid }); if (result.Count != 0) { if (result[0].EndDate.Day <= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month <= date.Month || result[0].EndDate.Day >= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month <= date.Month || result[0].EndDate.Day <= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month >= date.Month || result[0].EndDate.Day >= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month >= date.Month) { Model.ErrorWert = 4; return false; } Model.ErrorWert = 3; return false; } Model.ErrorWert = 1; return true; } private static DateTime ConvertTimeStringToDateTime(string timeString) { var dt = DateTime.Now.Date; if (string.IsNullOrEmpty(timeString)) { timeString = "0000"; } var numberString = Regex.Replace(timeString, "[^0-9]", ""); if (numberString.Length < 3) { if (numberString.Length < 2) { numberString = "0" + numberString; } while (numberString.Length < 4) { numberString = numberString + "0"; } } else { while (numberString.Length < 4) { numberString = "0" + numberString; } } if (numberString.Length > 4) { numberString = numberString.Substring(0, 4); } var hours = Convert.ToInt32(numberString.Substring(0, 2)); var minutes = Convert.ToInt32(numberString.Substring(2, 2)); dt = dt.AddHours(hours); dt = dt.AddMinutes(minutes); return dt; } private struct ValidationStruct { public List ValidationResults { get; set; } public Dictionary Rights { get; set; } public string MaxDaysEditServiceRecordsAllowed { get; set; } } public void SetViewMode() { if (Model == null) { RedirectToActionPermanent("Index", "Login"); return; } Model.SelectedCustomer = null; Model.SelectedCustomerOid = null; } public string GetSelectedSupportConceptCustomer() { return Model.SelectedSupportConcept == null ? "NoSupportConceptSelected" : SerializeObject(Model.SelectedSupportConcept.Customer.CustomerOid); } public string GetSelectedCustomer(long customerOid) { if (Model == null) { return "SessionTimeout"; } Model.SelectedCustomer = Model.Customers.FirstOrDefault(f => f.CustomerOid.HasValue && f.CustomerOid.Value.Equals(customerOid)); Model.SelectedCustomerOid = customerOid; return SerializeObject(GetJSONCustomer(Model.SelectedCustomer)); } private static JSONCustomer GetJSONCustomer(CustomerDC pCustomer) { return new JSONCustomer(pCustomer); } public void SetServiceRecordEmployee(long employeeOid) { if (Model == null) { RedirectToActionPermanent("Index", "Login"); return; } Model.SelectedEmployee = MainModel.AllEmployees.First(f => f.EmployeeOid.Equals(employeeOid)); } public string CheckToken(string token) { if(token != null && token.Equals("abcd")) { return SerializeObject("localhost;demo"); } return null; } } internal class JSONCustomer { public string Vorname { get; set; } public string Nachname { get; set; } public string Geburtstag { get; set; } public string Geschlecht { get; set; } public string Adresszusatz { get; set; } public string Strasse { get; set; } public string Postleitzahl { get; set; } public string Ort { get; set; } public string RechnungsadresseName { get; set; } public string RechnungsadresseStrasse { get; set; } public string RechnungsadressePostleitzahl { get; set; } public string RechnungsadresseOrt { get; set; } public string EMail { get; set; } public string Fax { get; set; } public string Telefon { get; set; } public string Handy { get; set; } public List Umfeldpersonen { get; set; } public JSONCustomer(CustomerDC init) { Vorname = init.FirstName; Nachname = init.LastName; Geburtstag = init.DateOfBirth?.ToShortDateString() ?? String.Empty; Geschlecht = init.Sex == Sex.Male ? "Männlich" : "Weiblich"; Adresszusatz = init.AddressLine1; Strasse = init.Street; Postleitzahl = init.PostalCode; Ort = init.Town; RechnungsadresseName = init.InvoiceAddressLine1; RechnungsadresseStrasse = init.InvoiceAddressStreet; RechnungsadressePostleitzahl = init.InvoiceAddressPostalCode; RechnungsadresseOrt = init.InvoiceAddressTown; foreach (var iContactDC in init.ContactInformations) { switch(iContactDC.ContactType) { case ContactType.business_Mail: EMail = iContactDC.ContactValue; break; case ContactType.business_Fax: Fax = iContactDC.ContactValue; break; case ContactType.business_Phone: Telefon = iContactDC.ContactValue; break; case ContactType.business_MobilePhone: Handy = iContactDC.ContactValue; break; } } Umfeldpersonen = new List(); foreach (var rel in init.EnvironmentPersons) { Umfeldpersonen.Add(new Umfeldsperson(rel)); } } } internal class Umfeldsperson { public string Vorname { get; set; } public string Nachname { get; set; } public string StrNameNr { get; set; } public string PLZOrt { get; set; } public string TelNr { get; set; } public string Mobil { get; set; } public string EMail { get; set; } public string Fax { get; set; } public string Rolle { get; set; } public string Titel { get; set; } public Umfeldsperson(CustomerPersonRelationDC umfeldspersonDC) { var person = umfeldspersonDC.Person; Rolle = person.Function; Vorname = person.FirstName; Nachname = person.LastName; StrNameNr = person.Street; PLZOrt = $"{person.PostalCode} {person.Town}"; TelNr = person.Communication1; Mobil = person.Communication2; EMail = person.Communication3; Fax = person.Communication4; Titel = person.Title; } } internal class TextbausteinDisplayItem { public string Name { get; set; } public long Oid { get; set; } public long? ParentOid { get; set; } public bool IsParent { get; set; } public string Text { get; set; } public List Children { get; set; } public TextbausteinDisplayItem(long pOid, string pName, long? pParentOid, bool pIsParent, string pText) { Oid = pOid; Name = pName; ParentOid = pParentOid; IsParent = pIsParent; Text = pText; Children = new List(); } } }