public List <ObjCust> SearchContacts(string searchString) { if (string.IsNullOrEmpty(searchString)) { return(null); } else { List <ObjCust> objCusts = new List <ObjCust>(); //требуется определить как искать по имени или телефону using (ObjCustContext objCustContext = new ObjCustContext()) { List <ObjCust> t = objCustContext.ObjCust.Where(x => x.RecordID != null && x.UserNumber != null).ToList(); List <ObjCust> t1 = new List <ObjCust>(); List <ObjectA28> objs = new List <ObjectA28>(); using (ObjectContext context = new ObjectContext()) { objs = context.ObjectA28.Where(x => x.RecordDeleted == false).ToList(); } foreach (ObjCust item in t) { if (objs.Any(x => x.ObjectID == item.ObjectID && x.RecordDeleted == false)) { t1.Add(item); } } string result = ""; string text = ""; foreach (char item in searchString.ToCharArray()) { if (char.IsDigit(item)) { result += item; } else if (char.IsLetter(item) || item == ' ') { text += item; } } result = CRMService.Helpers.HelpersMethods.NormalizePhone(result); //foreach (ObjCust item in t) { // if (item.) //} if (!string.IsNullOrEmpty(result)) { if (result.Length == 11 && (result.Substring(0, 2) == "89" || result.Substring(0, 2) == "79")) //значит у нас номер телефона мобильный { objCusts = t1.Where(x => x.N_ObjCustPhone1 == result || x.N_ObjCustPhone2 == result || x.N_ObjCustPhone3 == result || x.N_ObjCustPhone4 == result || x.N_ObjCustPhone5 == result || x.N_ObjCustTitle.Contains(result) && x.ObjectNumber != -1 ).ToList(); } if (result.Length == 7) //значит у нас номер телефона городской { objCusts = t1.Where(x => x.N_ObjCustPhone1 == result || x.N_ObjCustPhone2 == result || x.N_ObjCustPhone3 == result || x.N_ObjCustPhone4 == result || x.N_ObjCustPhone5 == result || x.N_ObjCustTitle.Contains(result) && x.ObjectNumber != -1 ).ToList(); } } else if (!string.IsNullOrEmpty(text)) //ищем по имени { objCusts = t1.Where(x => x.ObjCustName.ToLower().Contains(text.ToLower()) || x.ObjCustTitle.ToLower().Contains(text.ToLower()) ).ToList(); } //поиск по телефону using (ObjAdminContext objAdminContext = new ObjAdminContext()) { List <ObjAdmin> Fulladmins = objAdminContext.ObjAdmin.Where(x => x.RecordDeleted == false).ToList(); List <ObjAdmin> admins = Fulladmins.Where(x => x.N_AdminPhone == result).ToList(); if (admins.Any()) { foreach (ObjAdmin item in admins) { using (ObjectContext objectContext = new ObjectContext()) { foreach (ObjectA28 _item in objectContext.ObjectA28.Where(x => x.ObjAdminID == item.ObjAdminID)) { if (objCusts.Any(x => x.ObjectID == _item.ObjectID)) { objCusts.FirstOrDefault(x => x.ObjectID == _item.ObjectID).N_ObjCustTitle += Environment.NewLine + "Администратор(старый лк)"; } else { objCusts.Add(new ObjCust() { N_ObjCustPhone1 = item.AdminPhone, ObjCustName = item.AdminName, N_ObjCustTitle = "Администратор ЛК", ObjectID = _item.ObjectID, ObjectNumber = _item.ObjectNumber }); } } } } } else if (!string.IsNullOrEmpty(text)) { List <ObjAdmin> admins1 = Fulladmins.Where(x => x.AdminName.ToLower().Contains(text.ToLower())).ToList(); if (admins1.Any()) { foreach (ObjAdmin item in admins1) { using (ObjectContext objectContext = new ObjectContext()) { foreach (ObjectA28 _item in objectContext.ObjectA28.Where(x => x.ObjAdminID == item.ObjAdminID)) { objCusts.Add(new ObjCust() { N_ObjCustPhone1 = item.AdminPhone, ObjCustName = item.AdminName, N_ObjCustTitle = "Администратор ЛК", ObjectID = _item.ObjectID, ObjectNumber = _item.ObjectNumber }); } } } } } } return(objCusts); } } }
public ActionResult Info(string guardobjectId) { try { //var actualAreas = DB_BLL.GetUserAreas(); //if ((from a in actualAreas select a).Where(x => x.HrefLink == "/guardobject/").FirstOrDefault() == null) // return View(); //try //{ // ViewBag.CurrUser = User.Identity.Name.ToString(); //} //catch (Exception exc) { ViewBag.CurrUser = exc.Message; } //ViewBag.DTNow = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"); var strId = Int32.Parse(guardobjectId); List <Data.A28.ObjectA28> objects = new List <Data.A28.ObjectA28>(); List <EventTemp> eventTemps = new List <EventTemp>(); List <ObjType> objTypes = new List <ObjType>(); List <ObjExtField> objExtFields = new List <ObjExtField>(); List <ExtField> extFields = new List <ExtField>(); List <_extFields> _ExtFields = new List <_extFields>(); List <_additionalServices> _AdditionalServices = new List <_additionalServices>(); using (ObjectContext objectContext = new ObjectContext()) { using (EventTempContext eventTempContext = new EventTempContext()) { using (ObjTypeContext objTypeContext = new ObjTypeContext()) { using (ObjExtFieldContext objExtFieldContext = new ObjExtFieldContext()) { using (ExtFieldContext extFieldContext = new ExtFieldContext()) { int r = int.Parse(guardobjectId); objects = objectContext.ObjectA28.Where(x => x.RecordDeleted == false && x.ObjectID == r).ToList(); foreach (Data.A28.ObjectA28 item in objects) { eventTemps = eventTempContext.EventTemp.Where(x => x.RecordDeleted == false && x.EventTemplateID == item.EventTemplateID).ToList(); objTypes = objTypeContext.ObjType.Where(x => x.RecordDeleted == false && x.ObjTypeID == item.ObjTypeID).ToList(); objExtFields = objExtFieldContext.ObjExtField.Where(x => x.ObjectID == item.ObjectID).ToList(); foreach (ObjExtField _item in objExtFields) { if ((extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldID == 113) //|| (extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldID == 119) || (extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldID == 145) || (extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldID == 147) || (extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldID == 149)) { _ExtFields.Add(new _extFields( extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldName, _item.ExtFieldValue )); } if (extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldID == 119) { DateTime _dt; _ExtFields.Add(new _extFields( extFieldContext.ExtField.FirstOrDefault(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ExtFieldName, DateTime.TryParse(_item.ExtFieldValue, out _dt) ? _dt.ToString("dd.MM.yyyy") : _item.ExtFieldValue )); } //extFields = extFieldContext.ExtField.Where(x => x.RecordDeleted == false && x.ExtFieldID == _item.ExtFieldID).ToList(); } using (DeviceTypeContext deviceTypeContext = new DeviceTypeContext()) { string DeviceName = null; if (item.DeviceTypeID.HasValue) { DeviceName = deviceTypeContext.DeviceTypes.FirstOrDefault(x => x.DeviceTypeID == item.DeviceTypeID).Name; } if (!string.IsNullOrEmpty(DeviceName)) { _ExtFields.Add(new _extFields("Оборудование", DeviceName)); } } } } } } } } List <EPCustomer> ePCustomers = new List <EPCustomer>(); List <EP> ePs = new List <EP>(); using (EPCustomerContext ePCustomerContext = new EPCustomerContext()) { if (objects.Any()) { int onum = objects.FirstOrDefault().ObjectNumber; ePCustomers = ePCustomerContext.EPCustomer.Where(x => x.BeginningNumber <= onum && x.EndNumber >= onum).ToList(); using (EPContext ePContext = new EPContext()) { foreach (EPCustomer item in ePCustomers) { foreach (EP _item in ePContext.EP.Where(x => x.ProcID == item.OwnerRecordID && x.Enabled == true && x.ProcGroupID == 30)) { ePs.Add(_item); } //TODO: Вероятно номер телефона мы уже получили и дальше не надо ничего делать с смсками. } } } } if (ePs.Any()) { _AdditionalServices.Add(new _additionalServices("СМС", true)); } List <ObjAdmin> objAdmins = new List <ObjAdmin>(); using (ObjAdminContext objAdminContext = new ObjAdminContext()) { int objAdminID = 0; int.TryParse(objects.FirstOrDefault().ObjAdminID.ToString(), out objAdminID); if (objAdminID != 0) { objAdmins = objAdminContext.ObjAdmin.Where(x => x.RecordDeleted == false && x.ObjAdminID == objAdminID).ToList(); } } List <ObjCust> objCustsAdmins = new List <ObjCust>(); int objID = objects.FirstOrDefault().ObjectID; using (ObjCustContext objCustContext = new ObjCustContext()) { objCustsAdmins = objCustContext.ObjCust.Where(x => x.ObjectID == objID && (x.MyAlarmUserRole == 1 || x.MyAlarmUserRole == 2)).ToList(); } if (objAdmins.Any()) { foreach (ObjAdmin admin in objAdmins) { objCustsAdmins.Add(new ObjCust() { ObjCustName = admin.AdminName, ObjCustPhone1 = admin.AdminPhone, Role = "Администратор(старый ЛК)" }); } } if (!objAdmins.Any() && !objCustsAdmins.Any()) { objCustsAdmins.Add(new ObjCust() { ObjCustName = "Администраторов и пользователей ", ObjCustPhone1 = " нет" }); } List <ObjCust> objCusts = new List <ObjCust>(); //int objID = objects.FirstOrDefault().ObjectID; using (ObjCustContext objCustContext = new ObjCustContext()) { objCusts = objCustContext.ObjCust.Where(x => x.ObjectID == objID).ToList(); } List <ObjSchedule> objSchedules = new List <ObjSchedule>(); using (ObjScheduleContext objScheduleContext = new ObjScheduleContext()) { objSchedules = objScheduleContext.ObjSchedule.Where(x => x.ObjectID == objID).ToList(); if (objSchedules.Any()) { if (objects.Any(x => x.ArmSchedule_EarlyArm == true || x.ArmSchedule_LaterArm == true || x.ArmSchedule_EarlyDisarm == true || x.ArmSchedule_LaterDisarm == true)) { _AdditionalServices.Add(new _additionalServices("КР", true)); } } //if (objSchedules.Any()) { // _AdditionalServices.Add(new _additionalServices("КР", true)); //} //foreach (ObjectA28 item in objects) { // if (item.ArmSchedule_EarlyArm) // _AdditionalServices.Add(new _additionalServices("Взятие раньше времени", true)); // if (item.ArmSchedule_EarlyDisarm) // _AdditionalServices.Add(new _additionalServices("Снятие раньше времени", true)); // if (item.ArmSchedule_LaterArm) // _AdditionalServices.Add(new _additionalServices("Взятие позже времени", true)); // if (item.ArmSchedule_LaterDisarm) // _AdditionalServices.Add(new _additionalServices("Снятие позже времени", true)); //} } return(View(new GuardObjectModel() { Name = objects.FirstOrDefault().Name, Address = objects.FirstOrDefault().Address, //Number = objects.FirstOrDefault().ObjectNumber.ToString(), Number = Convert.ToString(objects.FirstOrDefault().ObjectNumber, 16), Sygnalizations = (objects.FirstOrDefault().IsArm ? " ОС " : null) + (objects.FirstOrDefault().IsFire ? " ПС " : null) + (objects.FirstOrDefault().IsPanic ? " ТРС " : null), ObjectType = objTypes.FirstOrDefault().ObjTypeName, EventTemplate = eventTemps.FirstOrDefault().EventTemplateName, ControlTime = int.TryParse(objects.FirstOrDefault().ControlTime.ToString(), out _) ? objects.FirstOrDefault().ControlTime.ToString() : "нет данных", ObjectPassword = objects.FirstOrDefault().ObjectPassword, Phone1 = objects.FirstOrDefault().Phone1, Phone2 = objects.FirstOrDefault().Phone2, Phone3 = objects.FirstOrDefault().Phone3, ExtFields = _ExtFields, Owners = objCusts, RemoteProgrammingGUID = string.IsNullOrEmpty(objects.FirstOrDefault().TransmitterID) ? "да" : "нет", CustAdmins = objCustsAdmins, SendSMS = ePs, addServices = _AdditionalServices //Name = obj.s.Name, //Address = obj.s.Address, //Number = obj.s.ObjectNumber.ToString("X"), //Sygnalizations = (obj.s.IsArm == true ? "Охранная " : "") + (obj.s.IsFire == true ? "Пожарная " : "") + (obj.s.IsPanic == true ? "Тревожная кнопка " : ""), //ObjectType = obj.t.ObjTypeName, //EventTemplate = obj.e.EventTemplateName, //ControlTime = obj.s.ControlTime == 0 ? "не задано" : obj.s.ControlTime.ToString(), //ObjectPassword = obj.s.ObjectPassword, //Phone1 = obj.s.Phone1, //Phone2 = obj.s.Phone2, //Phone3 = obj.s.Phone3, //ExtFields = objExtDict, //Owners = objOwnersList, //RemoteProgrammingGUID = string.IsNullOrEmpty(obj.s.TransmitterID) ? "нет" : "да" })); //using (var context = new A28Entities()) { // var obj = (from s in context.Object // join e in context.EventTemp on s.EventTemplateID equals e.EventTemplateID // join t in context.ObjType on s.ObjTypeID equals t.ObjTypeID // select new { s, e, t }).Where(x => x.s.RecordDeleted == false && x.s.ObjectID == strId).FirstOrDefault(); // var objExt = (from e in context.ObjExtField // join ef in context.ExtField // on e.ExtFieldID equals ef.ExtFieldID select new { e, ef }).Where(x => x.e.ObjectID == obj.s.ObjectID).AsEnumerable(); // var objExtDict = new Dictionary<string, string>(); // foreach (var e in objExt) { // if ((e.e.ExtFieldID == 113) || (e.e.ExtFieldID == 119) || (e.e.ExtFieldID == 145) || (e.e.ExtFieldID == 147) || (e.e.ExtFieldID == 149)) { // objExtDict.Add(e.ef.ExtFieldName, e.e.ExtFieldValue); // } // } // //поля на отправку СМС и ЛК // var actualObj = (from a in context.Object select a).Where(x => x.ObjectID == strId).FirstOrDefault(); // if (actualObj != null) { // //СМС // var epCustomers = (from e in context.EPCustomer select e).Where(x => (x.BeginningNumber <= actualObj.ObjectNumber) && (x.EndNumber >= actualObj.ObjectNumber)).AsEnumerable(); // var smsParams = ""; // foreach (var ep in epCustomers) { // var procs = (from p in context.EP select p).Where(x => (x.ProcID == ep.OwnerRecordID) && (x.ProcGroupID == 30) && (x.Enabled == true)).AsEnumerable(); // foreach (var proc in procs) { // var procParams = ""; // try { // procParams = proc.Params.Split(';')[0].Split('=')[1] + "\n"; // } // catch (Exception exc) { } // smsParams += procParams; // } // } // objExtDict.Add("Отправка СМС", smsParams); // //Доп. услуги // //ЛК(старый) // var objAdmin = (from a in context.ObjAdmin select a).Where(x => x.ObjAdminID == actualObj.ObjAdminID /*&& x.ObjectID == strId*/).FirstOrDefault(); // if (objAdmin != null) { // objExtDict.Add("Администратор (старый ЛК)", objAdmin.AdminName + " " + "тел. " + objAdmin.AdminPhone + " " + "email: " + objAdmin.AdminEmail); // } // //else // //{ // // objExtDict.Add("Администратор (старый ЛК)", ""); // //} // //ЛК MyAlarm // //2 - пользователь // //1 - администратор // var objAdminMyAlarm = (from a in context.ObjCust select a).Where(x => x.MyAlarmUserRole == 1 && x.ObjectID == strId); // if (objAdminMyAlarm.Any()) { // System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); // foreach (var item in objAdminMyAlarm) { // stringBuilder.AppendLine(item.ObjCustName + " " + "тел. " + item.ObjCustPhone1); // } // objExtDict.Add("Администратор(ы) (MyAlarm)", stringBuilder.ToString()); // } // else { // var objUsersMyAlarm = (from a in context.ObjCust select a).Where(x => x.MyAlarmUserRole == 2 && x.ObjectID == strId); // if (objUsersMyAlarm.Any()) { // System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); // foreach (var item in objUsersMyAlarm) { // stringBuilder.AppendLine(item.ObjCustName + " " + "тел. " + item.ObjCustPhone1); // } // objExtDict.Add("Пользователь(и) (MyAlarm)", stringBuilder.ToString()); // } // } // if (objAdmin == null && objAdminMyAlarm.Count() == 0) // objExtDict.Add("Администратор(ы)", " - "); // } // /////////////////////////// // var objOwners = (from o in context.ObjCust select o).Where(x => x.ObjectID == obj.s.ObjectID).OrderBy(x => x.UserNumber).AsEnumerable(); // var objOwnersList = new List<ObjCust>(); // foreach (var owner in objOwners) { // objOwnersList.Add(owner); // } // if (obj != null) { // return View(new GuardObjectModel() { // Name = obj.s.Name, // Address = obj.s.Address, // Number = obj.s.ObjectNumber.ToString("X"), // Sygnalizations = (obj.s.IsArm == true ? "Охранная " : "") + (obj.s.IsFire == true ? "Пожарная " : "") + (obj.s.IsPanic == true ? "Тревожная кнопка " : ""), // ObjectType = obj.t.ObjTypeName, // EventTemplate = obj.e.EventTemplateName, // ControlTime = obj.s.ControlTime == 0 ? "не задано" : obj.s.ControlTime.ToString(), // ObjectPassword = obj.s.ObjectPassword, // Phone1 = obj.s.Phone1, // Phone2 = obj.s.Phone2, // Phone3 = obj.s.Phone3, // ExtFields = objExtDict, // Owners = objOwnersList, // RemoteProgrammingGUID = string.IsNullOrEmpty(obj.s.TransmitterID) ? "нет" : "да" // }); // } //} //using (var context = new CRMServiceEntities()) //{ // var obj = (from s in context.GuardObjectExtention select s).Where(x => x.GuardObjectId == strId).FirstOrDefault(); // if (obj != null) // { // return View(new GuardObjectModel() // { // Name = obj.Name, // Address = obj.Address, // Number = obj.Number.ToString(), // NumberHex = obj.NumberHex, // Sygnalizations = (obj.IsArm == true ? "Охранная " : "") + (obj.IsFire == true ? "Пожарная " : "") + (obj.IsPanic == true ? "Тревожная кнопка " : ""), // ObjectType = obj.ObjTypeId.ToString(), // EventTemplate = obj.EventTemplateId.ToString(), // ControlTime = obj.ControlTime.HasValue ? (obj.ControlTime == 0 ? "не задано" : obj.ControlTime.ToString()) : "не задано", // ObjectPassword = obj.ObjectPassword, // Phone1 = obj.Phone1, // Phone2 = obj.Phone2, // Phone3 = obj.Phone3 // }); // } //} } catch (Exception exc) { ViewBag.ExceptionMessage = exc.Message; } return(View()); }