/// <summary> /// Удаление коммутатора /// </summary> /// <param name="switches">Коммутатор</param> /// <param name="idUser">Ун пользователя</param> /// <returns></returns> public ModelReturn <Swithe> DeleteSwitch(Swithe switches, int?idUser) { try { using (var context = new InventoryContext()) { var isExistSwitch = context.Database.SqlQuery <object>($"Select * From Swithes Where IdSwithes = {switches.IdSwithes} and IdUser is null and IdStatus is null"); if (isExistSwitch.Any()) { HistoryLog.HistoryLog log = new HistoryLog.HistoryLog(); DeleteModelDb(context, new Swithe() { IdSwithes = switches.IdSwithes }); log.GenerateHistory(switches.IdHistory, switches.IdSwithes, "Коммутатор", idUser, $"Модель: {switches.ModelSwithe?.NameModel} Сервисный номер: {switches.ServiceNum} Серийный номер: {switches.SerNum} Инвентарный номер: {switches.InventarNum}", "Произведено удаление!"); return(new ModelReturn <Swithe>("Коммутатор удален!", switches)); } return(new ModelReturn <Swithe>("Не возможно удалить коммутатор! Есть привязки к пользователю или к статусу!", switches, 1)); } } catch (Exception e) { Loggers.Log4NetLogger.Error(e); } return(new ModelReturn <Swithe>("При удалении Коммутатора возникли ошибки " + switches.IdSwithes + " произошла ошибка смотри log.txt", switches, 2)); }
/// <summary> /// Подписка на изменение Коммутаторов /// </summary> /// <param name="swithe">Коммутатор</param> public static void SubscribeSwithe(Swithe swithe) { IHubContext context = GlobalHost.ConnectionManager.GetHubContext <SignalRinventory>(); Loggers.Log4NetLogger.Info(new Exception("Модель Комутаторов рассылка пошла: " + swithe.IdSwithes + " " + swithe.Coment)); SerializeJson json = new SerializeJson(); context.Clients.All.SubscribeSwithe(json.JsonLibaryIgnoreDate(swithe)); }