public IHttpActionResult SavePersonLocation(PersonLocation entity) { return(ApiResult <bool>(() => { return PersonBusinessRules.SavePersonLocation(entity); })); }
public void InvalidPut() { // Arrange bool res = false; SQLiteServiceBase db = new SQLiteServiceBase(); PersonLocation obj = GetInvalidObject(); // Act try { int len = 0; if (db.GetPersonLocations() != null) { foreach (var c in db.GetPersonLocations()) { len++; } } if (len != 0) { db.Edit(len - 1, obj); } } catch (Exception) { res = true; } // Assert Assert.IsFalse(res); }
public async Task <PersonLocation> getFromDb(string ip) { PersonLocation returnObj = null; using (var reader = new DatabaseReader("App_Data/GeoLite2-City.mmdb")) { // Replace "City" with the appropriate method for your database, e.g., // "Country". var city = reader.City(ip); returnObj = new PersonLocation(city.City.Name, city.MostSpecificSubdivision.Name, city.Country.Name, city.Location.Latitude, city.Location.Longitude); //Console.WriteLine(returnObj.Country.IsoCode); // 'US' //Console.WriteLine(returnObj.Country.Name); // 'United States' //Console.WriteLine(returnObj.Country.Names["zh-CN"]); // '美国' //Console.WriteLine(returnObj.MostSpecificSubdivision.Name); // 'Minnesota' //Console.WriteLine(returnObj.MostSpecificSubdivision.IsoCode); // 'MN' //Console.WriteLine(returnObj.City.Name); // 'Minneapolis' //Console.WriteLine(returnObj.Postal.Code); // '55455' //Console.WriteLine(returnObj.Location.Latitude); // 44.9733 //Console.WriteLine(returnObj.Location.Longitude); // -93.2323 } return(returnObj); }
public async Task <IActionResult> PutPersonLocation([FromRoute] int id, [FromBody] PersonLocation personLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != personLocation.Id) { return(BadRequest()); } _context.Entry(personLocation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonLocationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <PersonLocation> addPersonLocation(int personId, int countyId, int subCountyId, int wardId, string village, string landmark, int userId) { try { PersonLocation personLocation = new PersonLocation() { PersonId = personId, County = countyId, SubCounty = subCountyId, Ward = wardId, Village = village, Location = "", SubLocation = "", LandMark = landmark, NearestHealthCentre = "", Active = false, DeleteFlag = false, CreateDate = DateTime.Now, CreatedBy = userId }; await _unitOfWork.Repository <PersonLocation>().AddAsync(personLocation); await _unitOfWork.SaveAsync(); return(personLocation); } catch (Exception e) { throw e; } }
/// <inheritdoc/> public void FromDelimitedString(string delimitedString, Separators separators) { Separators seps = separators ?? new Separators().UsingConfigurationValues(); string[] segments = delimitedString == null ? Array.Empty <string>() : delimitedString.Split(seps.FieldSeparator, StringSplitOptions.None); if (segments.Length > 0) { if (string.Compare(Id, segments[0], true, CultureInfo.CurrentCulture) != 0) { throw new ArgumentException($"{ nameof(delimitedString) } does not begin with the proper segment Id: '{ Id }{ seps.FieldSeparator }'.", nameof(delimitedString)); } } RoleInstanceId = segments.Length > 1 && segments[1].Length > 0 ? TypeSerializer.Deserialize <EntityIdentifier>(segments[1], false, seps) : null; ActionCode = segments.Length > 2 && segments[2].Length > 0 ? segments[2] : null; RoleRol = segments.Length > 3 && segments[3].Length > 0 ? TypeSerializer.Deserialize <CodedWithExceptions>(segments[3], false, seps) : null; RolePerson = segments.Length > 4 && segments[4].Length > 0 ? segments[4].Split(seps.FieldRepeatSeparator, StringSplitOptions.None).Select(x => TypeSerializer.Deserialize <ExtendedCompositeIdNumberAndNameForPersons>(x, false, seps)) : null; RoleBeginDateTime = segments.Length > 5 && segments[5].Length > 0 ? segments[5].ToNullableDateTime() : null; RoleEndDateTime = segments.Length > 6 && segments[6].Length > 0 ? segments[6].ToNullableDateTime() : null; RoleDuration = segments.Length > 7 && segments[7].Length > 0 ? TypeSerializer.Deserialize <CodedWithExceptions>(segments[7], false, seps) : null; RoleActionReason = segments.Length > 8 && segments[8].Length > 0 ? TypeSerializer.Deserialize <CodedWithExceptions>(segments[8], false, seps) : null; ProviderType = segments.Length > 9 && segments[9].Length > 0 ? segments[9].Split(seps.FieldRepeatSeparator, StringSplitOptions.None).Select(x => TypeSerializer.Deserialize <CodedWithExceptions>(x, false, seps)) : null; OrganizationUnitType = segments.Length > 10 && segments[10].Length > 0 ? TypeSerializer.Deserialize <CodedWithExceptions>(segments[10], false, seps) : null; OfficeHomeAddressBirthplace = segments.Length > 11 && segments[11].Length > 0 ? segments[11].Split(seps.FieldRepeatSeparator, StringSplitOptions.None).Select(x => TypeSerializer.Deserialize <ExtendedAddress>(x, false, seps)) : null; Phone = segments.Length > 12 && segments[12].Length > 0 ? segments[12].Split(seps.FieldRepeatSeparator, StringSplitOptions.None).Select(x => TypeSerializer.Deserialize <ExtendedTelecommunicationNumber>(x, false, seps)) : null; PersonsLocation = segments.Length > 13 && segments[13].Length > 0 ? TypeSerializer.Deserialize <PersonLocation>(segments[13], false, seps) : null; }
PersonLocation GetInvalidObject() { PersonLocation obj = new PersonLocation(); obj.LocationUsage = "Everywhere"; return(obj); }
public void DeletePersonLocation(int id) { PersonLocation obj = dataBase.PersonLocations.Find(id); if (obj != null) { dataBase.PersonLocations.Remove(obj); Update(); } }
PersonLocation GetValidObject() { PersonLocation obj = new PersonLocation(); obj.SubAdress = "this is my real adreess. call me later"; obj.LocationUsage = "Everywhere"; obj.Notes = "notes"; return(obj); }
public int UpdatePersonLocation(PersonLocation location) { using (UnitOfWork _unitOfWork = new UnitOfWork(new PersonContext())) { _unitOfWork.PersonLocationRepository.Update(location); _result = _unitOfWork.Complete(); _unitOfWork.Dispose(); return(_result); } }
public IActionResult Details(int personId, int locationId) { var personLocations = new PersonLocation(personId, locationId); Console.WriteLine(personId); Console.WriteLine(locationId); db.PersonLocation.Add(personLocations); db.SaveChanges(); return(RedirectToAction("Index")); }
public void FromDelimitedString_WithAllProperties_ReturnsCorrectlyInitializedFields() { IType expected = new PersonLocation { PointOfCare = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "1" }, Room = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "2" }, Bed = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "3" }, Facility = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "4" }, LocationStatus = "5", PersonLocationType = "6", Building = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "7" }, Floor = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "8" }, LocationDescription = "9", ComprehensiveLocationIdentifier = new EntityIdentifier { IsSubcomponent = true, EntityId = "10" }, AssigningAuthorityForLocation = new HierarchicDesignator { IsSubcomponent = true, NamespaceId = "11" } }; IType actual = new PersonLocation(); actual.FromDelimitedString("1^2^3^4^5^6^7^8^9^10^11"); expected.Should().BeEquivalentTo(actual); }
public int DeletePersonLocation(int id) { using (UnitOfWork _unitOfWork = new UnitOfWork(new PersonContext())) { PersonLocation location = _unitOfWork.PersonLocationRepository.GetById(id); _unitOfWork.PersonLocationRepository.Remove(location); _result = _unitOfWork.Complete(); _unitOfWork.Dispose(); return(_result); } }
public async Task <IActionResult> PostPersonLocation([FromBody] PersonLocation personLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.PersonLocation.Add(personLocation); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPersonLocation", new { id = personLocation.Id }, personLocation)); }
public async Task <Result <AddUpdatePersonLocationResponse> > Handle(AddUpdatePersonLocationCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { PersonLocation location = new PersonLocation(); PersonLocationService personLocationService = new PersonLocationService(_unitOfWork); List <PersonLocation> personLocationList = await personLocationService.GetPersonLocation(request.PersonId); if (personLocationList.Count > 0) { personLocationList[0].County = request.CountyId; personLocationList[0].SubCounty = request.SubCountyId; personLocationList[0].Ward = request.WardId; personLocationList[0].NearestHealthCentre = request.NearestHealthCentre; personLocationList[0].LandMark = request.LandMark; location = await personLocationService.UpdatePersonLocation(personLocationList[0]); } else { PersonLocation personLocation = new PersonLocation() { PersonId = request.PersonId, County = request.CountyId, SubCounty = request.SubCountyId, Ward = request.WardId, NearestHealthCentre = request.NearestHealthCentre, LandMark = request.LandMark, Village = "", Location = "", SubLocation = "", Active = false, DeleteFlag = false, CreateDate = DateTime.Now, CreatedBy = request.UserId }; location = await personLocationService.AddPersonLocation(personLocation); } return(Result <AddUpdatePersonLocationResponse> .Valid(new AddUpdatePersonLocationResponse() { Message = "Successful", PersonLocationId = location.Id })); } catch (Exception e) { return(Result <AddUpdatePersonLocationResponse> .Invalid(e.Message)); } } }
public PersonLocation GetPersonLocationId(int id) { PersonLocation obj = null; foreach (PersonLocation o in dataBase.PersonLocations) { if (o.== id) { obj = o; break; } } return(obj); }
public bool SavePersonLocation(PersonLocation entity) { if (entity.LocationId > 0 && entity.PersonId > 0) { LocationBusinessRules.SaveLocation(entity.Location); } else { entity.LocationId = LocationBusinessRules.SaveLocation(entity.Location); SqlPersonProvider.InsertPersonLocation(entity); } return(true); }
public async Task <Result <GetPersonDetailsResponse> > Handle(GetPersonDetailsCommand request, CancellationToken cancellationToken) { try { RegisterPersonService rs = new RegisterPersonService(_unitOfWork); int id = request.PersonId; if (request.PersonId > 0) { persondetail = await rs.GetPerson(id); personEducation = await rs.GetCurrentPersonEducation(id); personocc = await rs.GetCurrentOccupation(id); personmarital = await rs.GetFirstPatientMaritalStatus(id); personlocation = await rs.GetCurrentPersonLocation(id); personcontact = await rs.GetCurrentPersonContact(id); personemerg = await rs.GetCurrentPersonEmergency(id); pid = await rs.GetCurrentPersonIdentifier(id); pt = await rs.GetPatientByPersonId(id); } _unitOfWork.Dispose(); return(Result <GetPersonDetailsResponse> .Valid(new GetPersonDetailsResponse() { personDetail = persondetail, personEducation = personEducation, personOccupation = personocc, personMaritalStatus = personmarital, personLocation = personlocation, personContact = personcontact, PersonEmergencyView = personemerg, personIdentifier = pid, patient = pt })); } catch (Exception ex) { return(Result <GetPersonDetailsResponse> .Invalid(ex.Message)); } }
// POST api/PersonLocations public IHttpActionResult Post([FromBody] PersonLocation value) { try { db.Add(value); } catch (Exception ex) { ModelState.AddModelError(nameof(Country), ex.Message); return(BadRequest(ModelState)); } return(Ok()); }
// PUT api/PersonLocations/{id} public IHttpActionResult Put(int id, [FromBody] PersonLocation value) { try { db.Edit(id, value); } catch (Exception ex) { ModelState.AddModelError(nameof(PersonLocation), ex.Message); return(BadRequest(ModelState)); } return(Ok()); }
public async Task <PersonLocation> UpdatePersonLocation(PersonLocation personLocation) { try { _unitOfWork.Repository <PersonLocation>().Update(personLocation); await _unitOfWork.SaveAsync(); return(personLocation); } catch (Exception e) { Log.Error(e.Message + " " + e.InnerException); throw e; } }
public void ToDelimitedString_WithAllProperties_ReturnsCorrectlySequencedFields() { IType hl7Type = new PersonLocation { PointOfCare = new HierarchicDesignator { NamespaceId = "1" }, Room = new HierarchicDesignator { NamespaceId = "2" }, Bed = new HierarchicDesignator { NamespaceId = "3" }, Facility = new HierarchicDesignator { NamespaceId = "4" }, LocationStatus = "5", PersonLocationType = "6", Building = new HierarchicDesignator { NamespaceId = "7" }, Floor = new HierarchicDesignator { NamespaceId = "8" }, LocationDescription = "9", ComprehensiveLocationIdentifier = new EntityIdentifier { EntityId = "10" }, AssigningAuthorityForLocation = new HierarchicDesignator { NamespaceId = "11" } }; string expected = "1^2^3^4^5^6^7^8^9^10^11"; string actual = hl7Type.ToDelimitedString(); Assert.Equal(expected, actual); }
internal PersonLocation GetPersonLocation(int fieldIndex) { PersonLocation pl = new PersonLocation(); string fieldValue = GetField(fieldIndex); pl.PointOfCare = GetComponent(fieldValue, 0); pl.Room = GetComponent(fieldValue, 1); pl.Bed = GetComponent(fieldValue, 2); pl.Facility = GetComponent(fieldValue, 3); pl.LocationStatus = GetComponent(fieldValue, 4); pl.PersonLocationType = GetComponent(fieldValue, 5); pl.Building = GetComponent(fieldValue, 6); pl.Floor = GetComponent(fieldValue, 7); pl.LocationDescription = GetComponent(fieldValue, 8); return(pl); }
public int AddPersonLocation(int personId, int county, int subcounty, int ward, string village, string location, string sublocation, string landmark, string nearesthealthcentre, int userId) { PersonLocation personLocation = new PersonLocation() { PersonId = personId, County = county, SubCounty = subcounty, Ward = ward, Village = village, Location = location, SubLocation = sublocation, LandMark = landmark, NearestHealthCentre = nearesthealthcentre, CreatedBy = userId }; return(_result = _mgr.AddPersonLocation(personLocation)); }
public void Edit(int id, PersonLocation obj) { using (var context = new ApplicationContext()) { var temp = context.PersonLocations.FirstOrDefault(_ => _.LocationsLocationId == id); try { if (temp != null) { temp.SubAdress = obj.SubAdress; temp.LocationUsage = obj.LocationUsage; temp.Notes = obj.Notes; context.SaveChanges(); } } catch (Exception) { /*TO DO*/ } } }
public void Edit(int id, PersonLocation obj) { using (var context = new ApplicationContext()) { var temp = context.PersonLocations.FirstOrDefault(_ => _.== id); try { if (temp != null) { // // change properties // context.SaveChanges(); } } catch (Exception) { /*TO DO*/ } } }
public void InvalidPost() { // Arrange bool res = false; SQLiteServiceBase db = new SQLiteServiceBase(); PersonLocation obj = GetValidObject(); // Act try { db.Add(obj); } catch (Exception) { res = true; } // Assert Assert.IsFalse(res); }
public async Task <IActionResult> Index() { var model = new Locator(); Regex regexIp = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"); model.ip = GetRequestIP(); try { model.ip = model.ip.Split(':', StringSplitOptions.RemoveEmptyEntries)[0]; } catch (Exception e) { Console.WriteLine(e); } HttpClient client = new HttpClient(); PersonLocation newModel = null; if (regexIp.Match(model.ip).Success) { newModel = await getFromDb(model.ip); } else { model.ip = "Defined to: 177.156.131.41"; newModel = await getFromDb("177.156.131.41"); } if (newModel != null) { model.Location = newModel; } return(View(model)); }
/// <inheritdoc/> public void FromDelimitedString(string delimitedString, Separators separators) { Separators seps = separators ?? new Separators().UsingConfigurationValues(); string[] segments = delimitedString == null ? Array.Empty <string>() : delimitedString.Split(seps.FieldSeparator, StringSplitOptions.None); if (segments.Length > 0) { if (string.Compare(Id, segments[0], true, CultureInfo.CurrentCulture) != 0) { throw new ArgumentException($"{ nameof(delimitedString) } does not begin with the proper segment Id: '{ Id }{ seps.FieldSeparator }'.", nameof(delimitedString)); } } PrimaryKeyValueLrl = segments.Length > 1 && segments[1].Length > 0 ? TypeSerializer.Deserialize <PersonLocation>(segments[1], false, seps) : null; SegmentActionCode = segments.Length > 2 && segments[2].Length > 0 ? segments[2] : null; SegmentUniqueKey = segments.Length > 3 && segments[3].Length > 0 ? TypeSerializer.Deserialize <EntityIdentifier>(segments[3], false, seps) : null; LocationRelationshipId = segments.Length > 4 && segments[4].Length > 0 ? TypeSerializer.Deserialize <CodedWithExceptions>(segments[4], false, seps) : null; OrganizationalLocationRelationshipValue = segments.Length > 5 && segments[5].Length > 0 ? segments[5].Split(seps.FieldRepeatSeparator, StringSplitOptions.None).Select(x => TypeSerializer.Deserialize <ExtendedCompositeNameAndIdNumberForOrganizations>(x, false, seps)) : null; PatientLocationRelationshipValue = segments.Length > 6 && segments[6].Length > 0 ? TypeSerializer.Deserialize <PersonLocation>(segments[6], false, seps) : null; }
public int UpdatePersonLocation(PersonLocation personLocation) { return(_result = _mgr.UpdatePersonLocation(personLocation)); }