public NextAction CheckAuthorizationTerminal(string terminalSessionKey, string path) { NextAction nextAction = new NextAction(); RelationKeyOMS_OMSDataDBModel relation = null; using (DataBaseContext db = new DataBaseContext()) { try { relation = db.RelationOMS_OMSDatas?.Where(d => d.KeyLpu == terminalSessionKey).FirstOrDefault(); } catch { ErrorModel errorModel = new ErrorModel(); errorModel.IdError = "CheckAuthorizationTerminal_ErrorConnectDB"; errorModel.TextError = "Ошибка подключения к БД"; nextAction.path = "~/Views/Home/ErrorPage.cshtml"; nextAction.obj = errorModel; return(nextAction); } if (relation == null) { nextAction.path = "~/Views/AdminPanel/AdminPanelIndex.cshtml"; return(nextAction); } else { nextAction.path = "~/Views/Authorization/Authorization.cshtml"; nextAction.obj = relation; return(nextAction); } } }
public void AddTerminalToDataBase(string keyLpu, string idLpu, string nameLpu, string addressLpu) { try { using (DataBaseContext db = new DataBaseContext()) { RelationKeyOMS_OMSDataDBModel terminal = null; terminal = db.RelationOMS_OMSDatas.Where(t => t.KeyLpu == keyLpu).FirstOrDefault(); if (terminal != null) { terminal.IdLpu = idLpu; terminal.NameLpu = nameLpu; terminal.AddressLpu = addressLpu; } else { RelationKeyOMS_OMSDataDBModel newTerminal = new RelationKeyOMS_OMSDataDBModel(); newTerminal.KeyLpu = keyLpu; newTerminal.IdLpu = idLpu; newTerminal.NameLpu = nameLpu; newTerminal.AddressLpu = addressLpu; db.RelationOMS_OMSDatas.Add(newTerminal); } db.SaveChanges(); } } catch { } }