public void AddLocations() { try { string[] lines = File.ReadAllLines(@"../../Location.txt"); List <string> list = new List <string>(); for (int i = 0; i < lines.Length; i++) { tblLocation location = new tblLocation(); list = lines[i].Split(',').ToList(); location.Adress = list[0]; location.Place = list[1]; location.States = list[2]; using (DAN_LXEntities1 context = new DAN_LXEntities1()) { if (context.tblLocations.Where(x => x.Adress == location.Adress && x.Place == location.Place && x.States == location.States).ToList().Count == 0) { context.tblLocations.Add(location); context.SaveChanges(); } } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public void ReadLocationFromFile(List <tblLocation> location) { string file = @"~\..\..\..\Locations.txt"; int id = 0; using (WorkerContext context = new WorkerContext()) { if (File.Exists(file)) { string[] readFile = File.ReadAllLines(file); for (int i = 0; i < readFile.Length; i++) { if (!string.IsNullOrEmpty(readFile[i])) { string[] trim = readFile[i].Split(','); string address = trim[0]; string city = trim[1]; string country = trim[2]; id++; tblLocation s = new tblLocation(id, address, city, country); location.Add(s); context.tblLocations.Add(s); context.SaveChanges(); } } } } }
//Insert the location into the db, and generate a new Id for it. public int Insert() { try { using (MusicEntities dc = new MusicEntities()) { //Create a new Id this.Id = Guid.NewGuid(); //Set the properties tblLocation location = new tblLocation { Id = this.Id, Description = this.Description }; //Add it to the table and save changes dc.tblLocations.Add(location); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static List <tblLocation> LoadLocations() { string line; try { using (StreamReader streamReader = new StreamReader(pathLocation)) { while ((line = streamReader.ReadLine()) != null) { tblLocation location = new tblLocation(); string[] lines = line.Split(','); location.Address = lines.ElementAt(0).ToString(); location.City = lines.ElementAt(1).ToString(); location.Country = lines.ElementAt(2).ToString(); listOfLocationsFromFile.Add(location); } } } catch (Exception e) { Console.WriteLine("Not possible to read from file {0} or file doesn't exist.", pathLocation); Console.WriteLine(e.Message); } return(listOfLocationsFromFile); }
public tblLocation AddLocation(tblLocation location) { try { using (EmployeeDbEntities1 context = new EmployeeDbEntities1()) { tblLocation newLocation = new tblLocation(); newLocation.City = location.City; newLocation.Number = location.Number; newLocation.Street = location.Street; newLocation.Country = location.Country; context.tblLocations.Add(newLocation); context.SaveChanges(); location.LocationID = newLocation.LocationID; return(location); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
protected void imgAddLoc_Click(object sender, ImageClickEventArgs e) { if (string.IsNullOrEmpty(txtAddLocations.Text)) { ShowClientFunction("alert('Please enter a location before submitting!');"); return; } try { if (NumRecords(1) >= 0) { if (txtAddLocations.Text != string.Empty) { if (!CheckIfExists(0, txtAddLocations.Text)) { tblLocation tloc = new tblLocation(); tloc.LocationName = txtAddLocations.Text; tloc.newId = Guid.Parse(userId); locDB.tblLocations.InsertOnSubmit(tloc); locDB.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict); txtAddLocations.Text = string.Empty; ddlAddLocation.Items.Clear(); LoadLocations(); } } } } catch (Exception) { Response.Redirect("Error.aspx", false); } }
public ActionResult Delete(int?id, tblLocation location) { try { //tblLocation location=new tblLocation(); if (ModelState.IsValid) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } location = db.tblLocations.Find(id); if (location == null) { return(HttpNotFound()); } db.tblLocations.Remove(location); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); } catch { return(View()); } }
public async Task <LocationCreateModel> CreateLocation(LocationCreateModel data) { try { LocationCreateModel model = null; tblLocation dataLocation = await Task.Run(() => ManageLocation.InsertLocation(data.ConvertTotblLocation())); model = (await Task.Run(() => ManageLocation.GetLocationDetails(dataLocation.ID))).ConvertToLocation(); data.locationId = model.id; switch (data.companyType) { case "MSP": tblMSPLocationBranch dataMSP = await Task.Run(() => ManageMSP.InsertMSPLocationBranch(data.ConvertTotblMSPLocationBranch())); break; case "Customer": tblCustomerLocationBranch dataCustomer = await Task.Run(() => ManageCustomer.InsertCustomerLocationBranch(data.ConvertTotblCustomerLocationBranch())); break; case "Supplier": tblSupplierLocationBranch dataSupplier = await Task.Run(() => ManageSupplier.InsertSupplierLocationBranch(data.ConvertTotblSupplierLocationBranch())); break; } return(model); } catch (Exception) { throw; } }
public ActionResult DeleteConfirmed(long id) { tblLocation tbllocation = db.tblLocations.Find(id); db.tblLocations.Remove(tbllocation); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task SaveDetail() { //Setup(); try { Location loc = new Location(); loc.ClientID = ClientSelectedValue; loc.InstitutionID = InsSelectedValue; loc.BuildingTypeID = BuildingSelectedValue; loc.JobTypeID = JobTypeSelectedValue; loc.JobStatusID = JobStatusSelectedValue; loc.JobDetail = JobStatus; loc.createon = DateTime.Now; loc.issupload = false; loc.isedit = false; _tblLocation = new tblLocation(); _tblLocation.Add(loc); App.Current.MainPage = new MainPageCS(new CameraPage(loc.LocationId, "Location")); //_tblLocation.Add(loc); //await Navigation.PushAsync(cam); //cam = new CameraPage(); //await Navigation.PopAsync(); //await Navigation.PushModalAsync(new CameraPage()); //new MainPageCS(new CameraPage()); //MainPageCS main = new MainPageCS(); //main.RedirectPage(typeof(CameraPage),"Upload Photos"); //cam.Refresh(); //try //{ // MasterPageItem item = new MasterPageItem // { // Title = "PPM", // IconSource = "", // TargetType = typeof(CameraPage) // }; // if (item != null) // { // //masterPage = new MasterPageCS(); // //Master = masterPage; // //(Page)Activator.CreateInstance(typeof(CameraPage)) // main.Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(CameraPage))); // } //} //catch (Exception ex) //{ // await App.Current.MainPage.DisplayAlert("Error", ex.Message, "Cancel"); //} } catch (System.Exception ex) { Status = ex.Message; await App.Current.MainPage.DisplayAlert("Error !!", ex.Message, "Cancel"); } }
public ActionResult Edit([Bind(Include = "locId,name,locNumber,source,description,createdBy,createdDate,updatedBy,updatedDate")] tblLocation tbllocation) { if (ModelState.IsValid) { db.Entry(tbllocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbllocation)); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,Latitude,Longitude")] tblLocation tblLocation) { if (ModelState.IsValid) { db.Entry(tblLocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblLocation)); }
LocationDto ConvertToLocationDto(tblLocation location) { LocationDto locationDto = new LocationDto(); locationDto.Location = string.Format("{0} {1} {2} {3}", location.Street, location.Number, location.City, location.Country); locationDto.ID = location.LocationID; return(locationDto); }
public AddNewWorkerViewModel(AddNewWorker workerViewOpen) { Worker = new tblWorker(); addNewWorker = workerViewOpen; NewSector = new tblSector(); NewLocation = new tblLocation(); Genders = GetAllGenders(); Locations = GetAllLocations(); addNewWorker = workerViewOpen; }
public tblLocation GetLocation(Location location) { tblLocation tblLocation = null; if (location.LocID != null) { Locations.TryGetValue(location.LocID.Value, out tblLocation); } return(tblLocation); }
static Dictionary <string, bool> pdfDayFolderExists = new Dictionary <string, bool>(); // key:20181101 --> true public static int PreparePDFFolderAndDirectoryId(string baseFolder, DateTime receivedDate, out string directoryId, out string pdfStorageFolder) { //the new directoryId will always in this format: 20181101 lock (_threadlock) // avoid to create same location id and directoryid { string volume = receivedDate.ToString("yyyy"); string dictKey = receivedDate.ToString("yyyyMMdd"); if (directoryIdDict.ContainsKey(dictKey)) { pdfStorageFolder = baseFolder + volume + "\\" + dictKey + "\\"; directoryId = directoryIdDict[dictKey]; return(1); } using (var db = new Odiss_OPG_BaseEntities()) { var directory = db.tblDirectories.SingleOrDefault(x => x.DirectoryID == dictKey); // the dictionaryId is like: 20181101 if (directory != null) // created previously { directoryId = dictKey; directoryIdDict.Add(dictKey, dictKey); // saved in dictionary, so we dont need to check db again and again pdfStorageFolder = baseFolder + volume + "\\" + dictKey + "\\"; return(1); } //need to create new directory //first prepare folder PrepareFolder(baseFolder, receivedDate); // insert records into tblLocation and tblDirectory table var loc1 = new tblLocation(); loc1.LocationId = dictKey; loc1.Volume = volume; loc1.RPath = baseFolder; var dir1 = new tblDirectory(); dir1.DirectoryID = dictKey; dir1.LocationID = dictKey; dir1.Directory = dictKey; db.Entry(loc1).State = EntityState.Added; db.Entry(dir1).State = EntityState.Added; db.SaveChanges(); directoryIdDict.Add(dictKey, dictKey); // saved in dictionary, so we dont need to check db again and again directoryId = dictKey; pdfStorageFolder = baseFolder + volume + "\\" + dictKey + "\\"; } return(1); } }
public ActionResult Create([Bind(Include = "Id,Name,Description,Latitude,Longitude")] tblLocation tblLocation) { if (ModelState.IsValid) { db.tblLocations.Add(tblLocation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblLocation)); }
public ActionResult Create(tblLocation location) { if (ModelState.IsValid) { db.tblLocations.Add(location); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); }
public ActionResult Create([Bind(Include = "locId,name,locNumber,source,description,createdBy,createdDate,updatedBy,updatedDate")] tblLocation tbllocation) { if (ModelState.IsValid) { db.tblLocations.Add(tbllocation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbllocation)); }
EmployeeDto ConvertToEmployeeDto(tblEmployee employee) { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.EmployeeID = employee.EmployeeID; employeeDto.FirstName = employee.FirstName; employeeDto.LastName = employee.LastName; if (employee.Gender.Equals("M")) { employeeDto.Gender = "male"; } else if (employee.Gender.Equals("F")) { employeeDto.Gender = "female"; } else { employeeDto.Gender = "other"; } employeeDto.DateOfBirth = employee.DateOfBirth; employeeDto.JMBG = employee.JMBG; employeeDto.IDNumber = employee.IDNumber; employeeDto.PhoneNumber = employee.PhoneNumber; employeeDto.ManagerId = employee.ManagerId; employeeDto.SectorID = employee.SectorID; employeeDto.LocationID = employee.LocationID; if (employee.SectorID != null) { tblSector sector = sectorService.GetSectorByID((int)employee.SectorID); employeeDto.SectorName = sector.SectorName; } if (employee.LocationID != null) { tblLocation location = locationService.GetLocationByID((int)employee.LocationID); employeeDto.LocationName = string.Format("{0} {1} {2}", location.Street, location.Number, location.City); } if (employee.ManagerId != null) { tblEmployee manager = employeeService.GetEmployeeByID((int)employee.ManagerId); employeeDto.ManagerName = string.Format("{0} {1} {2}", manager.FirstName, manager.LastName, manager.JMBG); } return(employeeDto); }
public EditEmployeeViewModel(EditEmployee editEmployeeOpen, EmployeeDto employeeEdit) { eventObject = new EventClass(); editEmployee = editEmployeeOpen; Employee = employeeEdit; selctedLocation = new LocationDto(); StartDate = (DateTime)employee.DateOfBirth; Sector = employee.SectorName; locationService = new LocationService(); employeeService = new EmployeeService(); sectorService = new SectorService(); potentialManagersInDb = employeeService.GetAllPotentialMenagers(); PotentialMenagers = ConvertManagerListToDto(potentialManagersInDb); PotentialMenagers = PotentialMenagers.Where(x => x.ID != Employee.EmployeeID).ToList(); locations = locationService.GetAllLocations().ToList(); tblLocation locataionForPresent = locationService.GetLocationByID((int)Employee.LocationID); tblEmployee managerToPresent = null; if (Employee.ManagerId != null) { managerToPresent = employeeService.GetEmployeeByID((int)Employee.ManagerId); } LocationList = ConvertLocationDtoList(locations); SelctedLocation = LocationList.Where(x => x.ID == locataionForPresent.LocationID).FirstOrDefault(); LocationList.OrderByDescending(x => x.Location); LocationList.Reverse(); //if (managerToPresent!=null) //{ // SelectedMenager = PotentialMenagers.Where(x=>x.ID==Employee.ManagerId).FirstOrDefault(); //} eventObject.ActionPerformed += ActionPerformed; oldEmployee = new EmployeeDto(); oldEmployee.FirstName = employee.FirstName; oldEmployee.LastName = employee.LastName; oldEmployee.JMBG = employee.JMBG; }
public async Task <LocationCreateModel> UpdateLocation(LocationCreateModel model) { try { tblLocation data = await Task.Run(() => ManageLocation.UpdateLocation(model.ConvertTotblLocation())); return(data.ConvertToLocation()); } catch (Exception) { throw; } }
// GET: Location/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblLocation location = db.tblLocations.Find(id); if (location == null) { return(HttpNotFound()); } return(View(location)); }
// GET: /Location/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblLocation tbllocation = db.tblLocations.Find(id); if (tbllocation == null) { return(HttpNotFound()); } return(View(tbllocation)); }
public static void AddLocationsToDatabase() { tblLocation location = new tblLocation(); List <string> locations = ReadLocationsFromFile(); foreach (var l in locations) { string[] locationData = l.Split(','); location.Street = locationData[0]; location.Number = locationData[1]; location.City = locationData[2]; location.Country = locationData[3]; service.AddLocation(location); } }
internal static async Task DeleteLocation(long Id) { try { using (db = new eMSPEntities()) { tblLocation obj = await db.tblLocations.FindAsync(Id); db.tblLocations.Remove(obj); int x = await Task.Run(() => db.SaveChangesAsync()); } } catch (Exception) { throw; } }
internal static async Task <tblLocation> UpdateLocation(tblLocation model) { try { using (db = new eMSPEntities()) { db.Entry(model).State = EntityState.Modified; int x = await Task.Run(() => db.SaveChangesAsync()); return(model); } } catch (Exception) { throw; } }
public ActionResult Edit(tblLocation location) { try { if (ModelState.IsValid) { db.Entry(location).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); } catch { return(View()); } }
internal static async Task <tblLocation> InsertLocation(tblLocation model) { try { using (db = new eMSPEntities()) { model = db.tblLocations.Add(model); int x = await Task.Run(() => db.SaveChangesAsync()); return(model); } } catch (Exception) { throw; } }
//Retrieve the location from the database with this Id public void LoadById() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve from the db tblLocation location = dc.tblLocations.FirstOrDefault(l => l.Id == this.Id); //Set this location's properties this.Description = location.Description; } } catch (Exception ex) { throw ex; } }