コード例 #1
0
        //Request
        private static void RecieveDataAndFill(string DateParameter, HomeControllerViewModel obj)
        {
            var url = "http://www.lb.lt/webservices/ExchangeRates/ExchangeRates.asmx/getExchangeRatesByDate?Date=" + DateParameter;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
                HttpResponseMessage response = client.GetAsync(url).Result;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var xdoc = XDocument.Parse(response.Content.ReadAsStringAsync().Result);

                    var res = xdoc.Descendants("item");
                    foreach (var element in res)
                    {
                        var currency   = element.Element("currency").Value;
                        var rate       = element.Element("rate").Value.Replace(".", ",");
                        var doubleRate = Math.Round(Convert.ToDouble(rate), 4);

                        obj.AllCurrencies.Add(new CurrencyModel(currency, doubleRate));
                    }
                }
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: twaser/m183
        public ActionResult Logs()
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = connString;
            SqlCommand cmd_credentials = new SqlCommand();

            cmd_credentials.CommandText = "SELECT * FROM [dbo].[UserLog] ul JOIN [dbo].[User] u ON ul.UserId = u.Id ORDER BY ul.CreatedOn DESC";
            cmd_credentials.Connection  = con;
            con.Open();
            SqlDataReader reader = cmd_credentials.ExecuteReader();

            if (reader.HasRows)
            {
                List <HomeControllerViewModel> model = new List <HomeControllerViewModel>();
                while (reader.Read())
                {
                    var log_entry = new HomeControllerViewModel();
                    log_entry.UserId       = reader.GetValue(10).ToString();
                    log_entry.LogId        = reader.GetValue(0).ToString();
                    log_entry.LogCreatedOn = reader.GetValue(7).ToString();
                    model.Add(log_entry);
                }

                return(View(model));
            }
            else
            {
                ViewBag.Message = "No Results found";
                return(View());
            }
        }
コード例 #3
0
        //Recieving and Seting DATA
        private HomeControllerViewModel GetData(String InputedDate)
        {
            HomeControllerViewModel Alldata = new HomeControllerViewModel();

            RecieveDataAndFill(InputedDate, Alldata);

            return(Alldata);
        }
コード例 #4
0
        //Compare Data and Create final List with Rate Difference
        private HomeControllerViewModel FinalList(HomeControllerViewModel FromDateCurrencyDataList, HomeControllerViewModel ToDateCurrencyDataList)
        {
            HomeControllerViewModel FinalResult = new HomeControllerViewModel();

            foreach (CurrencyModel SingleFromDateCurrencyData in FromDateCurrencyDataList.AllCurrencies)
            {
                var s       = ToDateCurrencyDataList.AllCurrencies.Where(SingleToDateCurrencyData => SingleToDateCurrencyData.CurrName == SingleFromDateCurrencyData.CurrName).Single();
                var DifName = SingleFromDateCurrencyData.CurrName;
                var DifRate = Math.Round(SingleFromDateCurrencyData.CurrRate - s.CurrRate, 4);
                FinalResult.AllCurrencies.Add(new CurrencyModel(DifName, DifRate));
            }

            return(FinalResult);
        }
コード例 #5
0
        public ViewResult Details(string id)
        {
            // throw new Exception("This is Demo Exception ");
            int      empid    = Convert.ToInt32(protector.Unprotect(id));
            Employee employee = _empployeeRepository.GetEmployee(empid);

            if (employee == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFound", empid));
            }
            HomeControllerViewModel homeControllerViewModel = new HomeControllerViewModel();

            homeControllerViewModel.Employee  = employee;
            homeControllerViewModel.PageTitle = "Employee Details";
            return(View(homeControllerViewModel));
        }
コード例 #6
0
        public ActionResult Logs()
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\VS\\M183\\Ressourcen_Projekt\\m183_project.mdf;" +
                                   "Integrated Security=True;Connect Timeout=30";

            // check the credentails from the database - caution: SQL Injection should be prevented additionally!
            SqlCommand cmd_credentials = new SqlCommand();

            cmd_credentials.CommandText = "SELECT * FROM [dbo].[UserLog] ul JOIN [dbo].[User] u ON ul.UserId = u.Id ORDER BY ul.CreatedOn DESC";
            cmd_credentials.Connection  = con;

            con.Open();

            SqlDataReader reader = cmd_credentials.ExecuteReader();

            if (reader.HasRows) // ok - result was found
            {
                // map the db-results into a list so razor can iterate over the results
                List <HomeControllerViewModel> model = new List <HomeControllerViewModel>();
                while (reader.Read())
                {
                    var log_entry = new HomeControllerViewModel(); // custom created view model

                    // 0 = LogId, 1 = UserId, 2 = IP
                    // 3 = Browser 4 = Action, 5 = Result, 6 = AdditionalInformation
                    // 7 = CreatedOn, 8 = ModifiedOn, 9 = Deletedon
                    // 10 = Id, 11 = Username, 12 = Password

                    log_entry.UserId       = reader.GetValue(10).ToString();
                    log_entry.LogId        = reader.GetValue(0).ToString();
                    log_entry.LogCreatedOn = reader.GetValue(7).ToString();
                    // to be continued ...

                    model.Add(log_entry);
                }

                return(View(model));
            }
            else
            {
                ViewBag.message = "No Results found";
                return(View());
            }
        }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: DarioSartori/M183
        public ActionResult Logs()
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = @"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\dario\\OneDrive\\Dokumente\\logging.mdf;Integrated Security=True;Connect Timeout=30";

            SqlCommand cmdCredentials = new SqlCommand();

            cmdCredentials.CommandText = "SELECT * FROM [dbo].[UserLog] ul JOIN [dbo].[User] u ON ul.UserId = u.Id ORDER BY ul.Createdon DESC";
            cmdCredentials.Connection  = con;

            con.Open();

            SqlDataReader reader = cmdCredentials.ExecuteReader();

            if (reader.HasRows)
            {
                List <HomeControllerViewModel> viewModel = new List <HomeControllerViewModel>();
                while (reader.Read())
                {
                    HomeControllerViewModel logEntry = new HomeControllerViewModel();

                    // 10 = Id
                    // 0 = LogId
                    // 7 = CreatedOn

                    logEntry.UserId       = reader.GetValue(10).ToString();
                    logEntry.LogId        = reader.GetValue(0).ToString();
                    logEntry.LogCreatedOn = reader.GetValue(7).ToString();

                    viewModel.Add(logEntry);
                }

                return(View(viewModel));
            }
            else
            {
                ViewBag.message = "No Entry found";
                return(View());
            }
        }
コード例 #8
0
ファイル: HomeController.cs プロジェクト: LucStr/M183
        public ActionResult Logs()
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Users\\kraemery\\Documents\\logging_intrusion_detection.mdf; Integrated Security = True; Connect Timeout = 30";

            // check credentials
            // prevent SQL injection
            SqlCommand cmd_credentials = new SqlCommand();

            //cmd_credentials.CommandText = "SELECT * FROM [dbo].[UserLog] ul JOIN [dbo].[User] u ON ul.UserId = u.Id ORDER BY ul.CreatedOn DESC";
            cmd_credentials.CommandText = "SELECT * FROM [dbo].[UserLog] ul ORDER BY ul.CreatedOn DESC";
            cmd_credentials.Connection  = connection;

            connection.Open();

            SqlDataReader reader = cmd_credentials.ExecuteReader();

            if (reader.HasRows)
            {
                List <HomeControllerViewModel> viewModels = new List <HomeControllerViewModel>();
                while (reader.Read())
                {
                    HomeControllerViewModel viewModel = new HomeControllerViewModel();
                    viewModel.UserId       = reader.GetValue(0).ToString();
                    viewModel.LogId        = reader.GetValue(1).ToString();
                    viewModel.LogCreatedOn = reader.GetValue(2).ToString();
                    // load other values too...

                    viewModels.Add(viewModel);
                }

                return(View(viewModels));
            }
            else
            {
                ViewBag.message = "No results found";
                return(View());
            }
        }
コード例 #9
0
        public ActionResult Logs()
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Patrick\\Documents\\logging_intrusion_detection.mdf;Integrated Security=True;Connect Timeout=30";

            // check the credentials from the database
            SqlCommand cmd_credentials = new SqlCommand();

            cmd_credentials.CommandText = "SELECT * FROM [dbo].[UserLog] ul JOIN [dbo].[User] u ON ul.UserId = u.Id ORDER BY ul.CreatedOn DESC";
            cmd_credentials.Connection  = con;

            con.Open();

            SqlDataReader reader = cmd_credentials.ExecuteReader();

            if (reader.Read()) // ok - result was found
            {
                // map the db-results into a list so razor can iterate over the results
                List <HomeControllerViewModel> model = new List <HomeControllerViewModel>();
                while (reader.Read())
                {
                    var log_entry = new HomeControllerViewModel(); // custom created view model


                    log_entry.UserId       = reader.GetValue(10).ToString();
                    log_entry.LogId        = reader.GetValue(0).ToString();
                    log_entry.LogCreatedOn = reader.GetValue(7).ToString();

                    model.Add(log_entry);
                }
                return(View(model));
            }
            else
            {
                ViewBag.message = "No Results found";
                return(View());
            }
        }
コード例 #10
0
        public ActionResult Logs()
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\MEINEDATEN\\DOCUMENTS\\LOGGING_INTRUSION_DETECTION.MDF;Integrated Security=True;Connect Timeout=30";

            SqlCommand cmd_credentials = new SqlCommand();

            cmd_credentials.CommandText = "SELECT * FROM [dbo].[User-Log] ul JOIN [dbo].[User] u ON ul.UserId = u.Id ORDER BY ul.CreatedOn DESC";
            cmd_credentials.Connection  = con;

            con.Open();

            SqlDataReader reader = cmd_credentials.ExecuteReader();

            if (reader.HasRows)
            {
                List <HomeControllerViewModel> model = new List <HomeControllerViewModel>();
                while (reader.Read())
                {
                    var log_entry = new HomeControllerViewModel();
                    log_entry.UserId       = reader.GetValue(10).ToString();
                    log_entry.LogId        = reader.GetValue(0).ToString();
                    log_entry.LogCreatedOn = reader.GetValue(7).ToString();

                    model.Add(log_entry);
                }

                return(View(model));
            }
            else
            {
                ViewBag.Message = "No Results found";
                return(View());
            }
        }
コード例 #11
0
        //Creates Empty Model
        private HomeControllerViewModel EmptyObject()
        {
            HomeControllerViewModel AllDataEmpty = new HomeControllerViewModel(new CurrencyModel("", 0));

            return(AllDataEmpty);
        }