public IEnumerable <safaricom_regions> Get() { using (LocationDBEntities entities = new LocationDBEntities()) { return(entities.safaricom_regions.ToList()); } }
public void ExportToExcell() { LocationDBEntities _dbContext = new LocationDBEntities(); int uid = Convert.ToInt32(Session["UserID"]); System.Data.DataTable dtMaps = new System.Data.DataTable(); dtMaps.Columns.AddRange(new DataColumn[3] { new DataColumn("Enlem"), new DataColumn("Boylam"), new DataColumn("Adres"), }); Map map = new Map(); dtMaps.Rows.Add(map.Latitude, map.Longitude, map.Address); string filename = DateTime.Now.ToShortDateString() + " Lokasyon Listesi"; var grid = new GridView(); grid.DataSource = dtMaps; grid.DataBind(); Response.ClearContent(); Response.Charset = "utf-8"; Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".xls"); Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
public static bool login(string username, string password) { using (LocationDBEntities dbContext = new LocationDBEntities()) { return(dbContext.Users.Any(user => user.UserName.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Password == password)); } }
public ActionResult Upload(FormCollection formCollection) { var mapList = new List <AWSServerless_Google_Geocoding_Mvc.Models.Map>(); if (Request != null) { HttpPostedFileBase file = Request.Files["FileUpload"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string fileName = file.FileName; string fileContentType = file.ContentType; byte[] fileBytes = new byte[file.ContentLength]; var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); using (var package = new ExcelPackage(file.InputStream)) { ExcelPackage.LicenseContext = LicenseContext.NonCommercial; var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 1; rowIterator <= noOfRow; rowIterator++) { var map = new AWSServerless_Google_Geocoding_Mvc.Models.Map(); map.UserID = null; map.Name = null; map.Latitude = workSheet.Cells[rowIterator, 3].Value.ToString(); map.Longitude = workSheet.Cells[rowIterator, 4].Value.ToString(); map.Address = workSheet.Cells[rowIterator, 5].Value.ToString(); mapList.Add(map); } } } } using (LocationDBEntities db = new LocationDBEntities()) { foreach (var item in mapList) { db.Map.Add(item); } db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult Index(UploadViewModel model) { if (ModelState.IsValid) { HttpPostedFileBase uploadFile = model.File; try { if (uploadFile.ContentLength > 0) { // Create save path and put the uploaded file in that location var fileName = Path.GetFileName(uploadFile.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/File_Uploads"), fileName); uploadFile.SaveAs(path); // Create FileLocation model database FileLocation newLocation = new FileLocation(); newLocation.LocationString = "~/App_Data/File_Uploads/" + uploadFile.FileName; // Add model object to database using (var db = new LocationDBEntities()) { db.FileLocations.Add(newLocation); db.SaveChanges(); } } ViewBag.Message = "File Upload Successful"; return(View()); } catch { ViewBag.Message = "File Upload Failed"; return(View()); } } else { ViewBag.Message = "Error Creating Upload Model"; return(View()); } }
public ActionResult Token(User User) { if (ModelState.IsValid) { using (LocationDBEntities db = new LocationDBEntities()) { var obj = db.User.Where(a => a.Username.Equals(User.Username) && a.Password.Equals(User.Password)).FirstOrDefault(); if (obj != null) { Session.Add("UserID", obj.UserId.ToString()); Session.Add("FirstName", obj.FirstName.ToString() + " " + obj.LastName.ToString()); return(RedirectToAction("Index", "Admin")); } } // LocationDBEntities db = new LocationDBEntities(); // var obj = db.User.Where(a => a.Username.Equals(User.Username) && a.Password.Equals(User.Password)).FirstOrDefault(); // if (obj != null) // { // HttpContext.Session.Add("UserID", obj.UserId.ToString()); // HttpContext.Session.Add("FirstName", obj.FirstName.ToString() + " " + obj.LastName.ToString()); // HttpCookie userIdCookie = new HttpCookie("UserID", obj.UserId.ToString()); // userIdCookie.Expires = DateTime.Now.AddDays(365); // HttpContext.Response.Cookies.Add(userIdCookie); // HttpCookie userNameCookie = new HttpCookie("FirstName", obj.FirstName.ToString()); // userNameCookie.Expires = DateTime.Now.AddDays(365); // HttpContext.Response.Cookies.Add(userNameCookie); // } // User user = new User(); // user.Username = User.Username; // user.Password = User.Password; // var json = JsonConvert.SerializeObject(user); // var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); // using (var client = new HttpClient()) // { // client.BaseAddress = new Uri("https://cp7u0uz8r9.execute-api.eu-west-2.amazonaws.com/Prod/"); // client.DefaultRequestHeaders.Accept.Clear(); // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // HttpResponseMessage response = client.PostAsync("api/login/accesstoken", stringContent).Result; // if (response.IsSuccessStatusCode) // { // return RedirectToAction("Index", "Admin"); // } // return RedirectToAction("Login", "Login"); // } //} } return(RedirectToAction("Login", "Login")); }
public void SonExport(string fileName) { LocationDBEntities _dbContext = new LocationDBEntities(); int uid = Convert.ToInt32(Session["UserID"]); var lastFile = fileName; System.Data.DataTable dtMaps = new System.Data.DataTable(); dtMaps.Columns.AddRange(new DataColumn[4] { new DataColumn("Enlem"), new DataColumn("Boylam"), new DataColumn("Adres"), new DataColumn("Tarih"), }); List <Map> mapList = new List <Map>(); var query = (from m in _dbContext.Map where m.UserID == uid && m.FileName == lastFile select new { Latitude = m.Latitude, Longitude = m.Longitude, Address = m.Address, FileName = m.FileName, CreateHost = m.CreateHost, CreateDate = m.CreateDate, FileCount = m.FileCount }); mapList = query.ToList().Select(r => new Map { Latitude = r.Latitude, Longitude = r.Longitude, Address = r.Address, FileName = r.FileName, //LastFileName = r.LastFileName, CreateHost = r.CreateHost, CreateDate = Convert.ToDateTime(r.CreateDate.Value.ToShortDateString()), FileCount = r.FileCount }).ToList(); var isAlreadyExists = _dbContext.Map.Where(x => x.FileName.Equals(lastFile, StringComparison.InvariantCultureIgnoreCase)).Any(); if (isAlreadyExists) { mapList = query.ToList().Select(r => new Map { Latitude = r.Latitude, Longitude = r.Longitude, Address = r.Address, FileName = r.FileName, //LastFileName = r.LastFileName, CreateHost = r.CreateHost, CreateDate = Convert.ToDateTime(r.CreateDate.Value.ToShortDateString()), FileCount = r.FileCount }).ToList(); foreach (var map in mapList) { dtMaps.Rows.Add(map.Latitude.ToString().Replace('.', ','), map.Longitude.ToString().Replace('.', ','), map.Address, map.CreateDate.Value.ToShortDateString()); } } else { var maps = _dbContext.Map.Where(x => x.UserID == uid && x.FileName == lastFile).OrderByDescending(x => x.CreateDate).Take(50000).ToList(); foreach (var map in maps) { dtMaps.Rows.Add(map.Latitude.ToString().Replace('.', ','), map.Longitude.ToString().Replace('.', ','), map.Address, map.CreateDate.Value.ToShortDateString()); } } string filename = DateTime.Now.ToShortDateString() + " Lokasyon Listesi"; var grid = new GridView(); grid.DataSource = dtMaps; grid.DataBind(); Response.ClearContent(); Response.Charset = "utf-8"; Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".xls"); Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
public ActionResult Index(FormCollection formCollection) { LocationDBEntities db = new LocationDBEntities(); List <Map> mapList = new List <Map>(); if (Request != null) { HttpPostedFileBase file = Request.Files["FileUpload"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string fileNamee = file.FileName; string fileContentType = file.ContentType; byte[] fileBytes = new byte[file.ContentLength]; var path = Path.Combine(Server.MapPath("~/Content/FileUpload"), file.FileName); file.SaveAs(path); //Save(MapList,fileName,len); //using (var package = new ExcelPackage(file.InputStream)) //{ // ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // var currentSheet = package.Workbook.Worksheets; // var workSheet = currentSheet.First(); // var noOfCol = workSheet.Dimension.End.Column; // var noOfRow = workSheet.Dimension.End.Row; // for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) // { // var map = new Map(); // map.Address = workSheet.Cells[rowIterator, 3].Value.ToString(); // //map.UserID = Convert.ToInt32(Session["UserID"]); // //map.Address = workSheet.Cells[rowIterator, 3].Value.ToString(); // //map.LastFileName = Request.Cookies["sonYuklenenDosya"].Value; // //map.PrevFileName = Request.Cookies["oncekiYuklenenDosya"].Value; // //map.BeforeFileName = Request.Cookies["dahaOncekiYuklenenDosya"].Value; // //map.ModifyUserId = Convert.ToInt32(Session["UserID"]); // //map.ModifyUser = Session["FirstName"].ToString(); // //map.ModifyDate = DateTime.Now; // //map.CreateUserId = Convert.ToInt32(Session["UserID"]); // //map.CreateHost = Session["FirstName"].ToString(); // //map.CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // mapList.Add(map); // //map.FileCount = mapList.Count; // } // //ViewBag.ExcelPath = path; // //ViewBag.Path = path; //} } } //foreach (var item in mapList) //{ // db.Map.Add(item); //} //db.SaveChanges(); //ViewBag.Count = mapList.Count(); return(View(mapList)); //HttpPostedFileBase file = Request.Files["FileUpload"]; //var json = JsonConvert.SerializeObject( // new // { // files = file, // Passed = true, // Mesaj = "item added" // }, // new HttpPostedFileConverter()); //var stringContent = new StringContent(json, Encoding.UTF8, "multipart/form-data"); //try //{ // using (var client = new HttpClient()) // { // //var userid = Session["UserID"]; // client.BaseAddress = new Uri("https://cp7u0uz8r9.execute-api.eu-west-2.amazonaws.com/Prod/"); // client.DefaultRequestHeaders.Accept.Clear(); // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data")); // //HttpResponseMessage response = await client.PostAsJsonAsync("api/address/postmap?mapList=" + mapList).Result; // HttpResponseMessage response = client.PostAsync("api/address/save", stringContent).Result; // if (response.IsSuccessStatusCode) // { // return RedirectToAction("Index", "Admin"); // } // return null; // } //} //catch (Exception e) //{ // ViewBag.Hata = e.Message; //} //return RedirectToAction("Index", "Admin"); }
public ActionResult getArray(List <Map> MapList, string fileName, int len) { LocationDBEntities db = new LocationDBEntities(); List <Map> mapList = new List <Map>(); //int uid = Convert.ToInt32(Session["UserID"]); //var isAlreadyExists = db.Map.Where(x => x.UserID == uid && x.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).Any(); //if (isAlreadyExists) //{ // TempData["message"] = "Aynı isimde dosya daha önceden kaydedilmiş..."; // return Content(@"<script language='javascript' type='text/javascript'> // alert('Aynı isimde dosya daha önceden kaydedilmiş...'); // </script> // "); //} //else //{ //loop the MapList foreach (Map m in MapList) { var map = new Map(); map.UserID = Convert.ToInt32(Session["UserID"]); map.Latitude = m.Latitude; map.Longitude = m.Longitude; map.Address = m.Address; //map.ExcelPath = path; map.FileName = m.FileName; //map.LastFileName = Request.Cookies["sonYuklenenDosya"].Value; //map.PrevFileName = Request.Cookies["oncekiYuklenenDosya"].Value; //map.BeforeFileName = Request.Cookies["dahaOncekiYuklenenDosya"].Value; map.ModifyUserId = Convert.ToInt32(Session["UserID"]); map.ModifyUser = Session["FirstName"].ToString(); map.ModifyDate = DateTime.Now; map.CreateUserId = Convert.ToInt32(Session["UserID"]); map.CreateHost = Session["FirstName"].ToString(); map.CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); mapList.Add(map); map.FileCount = m.FileCount; foreach (var item in mapList) { db.Map.Add(item); } } //} db.SaveChanges(); return(Json(mapList, JsonRequestBehavior.AllowGet)); //} //LocationDBEntities db = new LocationDBEntities(); //List<Map> mapList = new List<Map>(); //var isAlreadyExists = db.Map.Where(x => x.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).Any(); //if (isAlreadyExists) //{ // TempData["message"] = "Aynı isimde dosya daha önceden kaydedilmiş..."; // return Content("<script language='javascript' type='text/javascript'>alert('Aynı isimde dosya daha önceden kaydedilmiş...');</script>"); //} //else //{ // //loop the MapList // foreach (Map m in MapList) // { // var map = new Map(); // map.UserID = Convert.ToInt32(Session["UserID"]); // map.Latitude = m.Latitude; // map.Longitude = m.Longitude; // map.Address = m.Address; // //map.ExcelPath = path; // map.FileName = m.FileName; // map.LastFileName = Request.Cookies["sonYuklenenDosya"].Value; // map.PrevFileName = Request.Cookies["oncekiYuklenenDosya"].Value; // map.BeforeFileName = Request.Cookies["dahaOncekiYuklenenDosya"].Value; // map.ModifyUserId = Convert.ToInt32(Session["UserID"]); // map.ModifyUser = Session["FirstName"].ToString(); // map.ModifyDate = DateTime.Now; // map.CreateUserId = Convert.ToInt32(Session["UserID"]); // map.CreateHost = Session["FirstName"].ToString(); // map.CreateDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // mapList.Add(map); // map.FileCount = m.FileCount; // } // foreach (var item in mapList) // { // db.Map.Add(item); // } // db.SaveChanges(); // return Json(mapList); //} }
public LocationRepository(LocationDBEntities dbContext) : base(dbContext) { }
public Repository(LocationDBEntities dbContext) { _dbContext = dbContext; }