public ActionResult Index(string inputID, string inputName, string inputPlaceN, string inputLine, string inputTurno) { Logger.InitLogger(); if (inputID == "" || inputName == "" || inputPlaceN == "" || inputLine == "" || inputTurno == "") { return(Content("<script language='javascript' type='text/javascript'>alert('Одно из полей пусто!');window.location.href = 'Index';</script>")); } else { try { using (SqlConnection cn = new SqlConnection()) { cn.ConnectionString = @"Data Source=patrin.ddns.net,1433;Initial Catalog=OIProject;Persist Security Info=True;User ID=sa;Password=18swlgnm"; cn.Open(); using (SqlCommand command = cn.CreateCommand()) { command.CommandText = string.Format("INSERT INTO Employee (ID, PlaceN, Line, Name, Turno) VALUES ('{0}','{1}','{2}','{3}','{4}')", inputID, inputPlaceN, inputLine, inputName, inputTurno); command.ExecuteNonQuery(); command.CommandText = string.Format("INSERT INTO Auth (ID, Password, Powers) VALUES ('{0}','{1}','{2}')", inputID, "0000", "Работник"); command.ExecuteNonQuery(); } cn.Close(); Employess load = new Employess(); Tablets load_tab = new Tablets(); Defects load_def = new Defects(); ArrayList allData = new ArrayList(); load.LoadData(); load_tab.PingAndLoadTablets(); load_def.LoadDefects(); allData.Add(load); allData.Add(load_def); allData.Add(load_tab); Logger.Log.Info("Добавление работника в БД"); return(View(allData)); } } catch (Exception ex) { Logger.Log.Error(ex.Message); return(Content("<script language='javascript' type='text/javascript'>alert('Ошибка в ходе добавления!" + ex.Message + "');window.location.href = 'Index';</script>")); } } }
public ActionResult Index() { try { Logger.InitLogger(); ClaimsIdentity user = (ClaimsIdentity)(User.Identity); string type = string.Empty; string right = string.Empty; IEnumerable <Claim> claims = user.Claims; try { type = claims.ElementAt(4).Type; right = claims.ElementAt(4).Value; } catch (Exception ex) { Logger.Log.Error("Попытка несанкционированного доступа!" + ex.Message); return(Redirect("/Account/Login")); } if (type == "Rights" && right == "Администратор" || right == "Работник ОК") { string browser = HttpContext.Request.Browser.Browser; string user_agent = HttpContext.Request.UserAgent; Employess load = new Employess(); Tablets load_tab = new Tablets(); Defects load_def = new Defects(); ArrayList allData = new ArrayList(); load.LoadData(); load_tab.PingAndLoadTablets(); load_def.LoadDefects(); allData.Add(load); allData.Add(load_def); allData.Add(load_tab); if (user_agent.Contains("Chrome") || (user_agent.Contains("Mozilla"))) { Logger.Log.Info("Загружена главная страница"); return(View(allData)); } else { return(Content("<script language='javascript' type='text/javascript'>alert('Сайт в данном браузере работает некорректно! Дальнейшая работа невозможна!');window.location.href = 'Index';</script>")); } } else { return(View("ErrorRight")); } } catch (Exception ex) { return(Content("<script language='javascript' type='text/javascript'>alert('Ошибка загрузки главной страницы!" + ex.Message + "');window.location.href = 'Index';</script>")); } }