public String DeleteServiceArea(ServiceArea servicesrea) { db.ServiceAreas.Remove(servicesrea); db.SaveChanges(); return "Success"; }
public String CreateServiceArea(ServiceArea servicesrea) { db.ServiceAreas.Add(servicesrea); db.SaveChanges(); return "Success"; }
public String EditServiceArea(ServiceArea servicesrea) { db.Entry(servicesrea).State = EntityState.Modified; db.SaveChanges(); return "Success"; }
private void AddServiceArea(int x, int y, ServiceArea serviceArea) { DataGridViewImageCell cell = (DataGridViewImageCell)field.Rows[y].Cells[x]; cell.Value = ServiceArea.Image; cell.Tag = serviceArea; }
/// <summary> /// Adds a service area to the system, only if it does not exist. /// </summary> private static void AddInitialServiceArea(this IDbAppContext context, ServiceArea initialServiceArea) { ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(initialServiceArea.MinistryServiceAreaID); if (serviceArea != null) { return; } serviceArea = new ServiceArea(); serviceArea.MinistryServiceAreaID = initialServiceArea.MinistryServiceAreaID; serviceArea.Name = initialServiceArea.Name; serviceArea.StartDate = initialServiceArea.StartDate; if (initialServiceArea.District != null) { District district = context.GetDistrictByMinistryDistrictId(initialServiceArea.District.MinistryDistrictID); serviceArea.District = district; } else { serviceArea.District = null; } context.ServiceAreas.Add(serviceArea); context.SaveChanges(); }
public PatientService(CurrentSession session, int patientId, int moduleId) { int locationId, userId; locationId = session.Facility.Id; patientId = Convert.ToInt32(HttpContext.Current.Session["patientId"]); userId = session.User.Id; IPatientHome pHome = (IPatientHome)ObjectFactory.CreateInstance("BusinessProcess.Clinical.BPatientHome, BusinessProcess.Clinical"); CurrentPatient = pHome.GetPatientById(patientId); CurrentServiceArea = session.Facility.Modules.Where(m => m.Id == moduleId).FirstOrDefault(); if (CurrentServiceArea != null && CurrentServiceArea.Clinical) { Formset = this.GetFormsForPatientAndModule(locationId, moduleId, userId, this.CurrentPatient); FormUrl = StaticFormMap.FormUrl; this.formLoaded = true; } else { this.formLoaded = false; Formset = null; FormUrl = null; } }
/// <summary> /// Test the owner search. Specifically test that searches for two items on a multi-select show the expected number of results. /// </summary> /// public async Task TestOwnerSearch() { /* Test plan: * 1. create 3 local areas. * 2. put 2 owners in each area. * 3. search for owners in local area 1 - should get 2 results. * 4. search for owners in local area 2 - should get 2 results. * 5. search for owners in local areas 1,2 - should get 4 results. * remove the owners * remove the local areas. */ string initialName = "InitialName"; // create 3 local areas. ServiceArea serviceArea = CreateServiceArea(initialName); LocalArea localArea1 = CreateLocalArea(serviceArea, "Local Area 1"); LocalArea localArea2 = CreateLocalArea(serviceArea, "Local Area 2"); LocalArea localArea3 = CreateLocalArea(serviceArea, "Local Area 3"); // create 2 owners in each. Owner owner1 = CreateOwner(localArea1, "Owner 1"); Owner owner2 = CreateOwner(localArea1, "Owner 2"); Owner owner3 = CreateOwner(localArea2, "Owner 3"); Owner owner4 = CreateOwner(localArea2, "Owner 4"); Owner owner5 = CreateOwner(localArea3, "Owner 5"); Owner owner6 = CreateOwner(localArea3, "Owner 6"); Owner[] searchresults = await OwnerSearchHelper("?localareas=" + localArea2.Id); Assert.Equal(2, searchresults.Length); searchresults = await OwnerSearchHelper("?localareas=" + localArea2.Id); Assert.Equal(2, searchresults.Length); searchresults = await OwnerSearchHelper("?localareas=" + localArea1.Id + "%2C" + localArea2.Id); Assert.Equal(4, searchresults.Length); searchresults = await OwnerSearchHelper("?owner=" + owner1.Id); Assert.Single(searchresults); // cleanup DeleteOwner(owner1); DeleteOwner(owner2); DeleteOwner(owner3); DeleteOwner(owner4); DeleteOwner(owner5); DeleteOwner(owner6); DeleteLocalArea(localArea1); DeleteLocalArea(localArea2); DeleteLocalArea(localArea3); DeleteServiceArea(serviceArea); }
private void AdjustRecord(ServiceArea item) { if (item != null && item.District != null) { item.District = _context.Districts.FirstOrDefault(a => a.Id == item.District.Id); } }
public static void UpdateSeedServiceAreaInfo(this DbAppContext context, ServiceArea serviceAreaInfo) { // Adjust the district. int ministry_district_id = serviceAreaInfo.District.MinistryDistrictID; var exists = context.Districts.Any(a => a.MinistryDistrictID == ministry_district_id); if (exists) { District district = context.Districts.First(a => a.MinistryDistrictID == ministry_district_id); serviceAreaInfo.District = district; } else { serviceAreaInfo.District = null; } ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(serviceAreaInfo.MinistryServiceAreaID); if (serviceArea == null) { context.ServiceAreas.Add(serviceAreaInfo); } else { serviceArea.Name = serviceAreaInfo.Name; serviceArea.StartDate = serviceAreaInfo.StartDate; serviceArea.District = serviceAreaInfo.District; } }
public PatientService(int locationId, int userId, Patient p, ServiceArea s) { this.CurrentPatient = p; this.CurrentServiceArea = s; this.Formset = this.GetFormsForPatientAndModule(locationId, s.Id, userId, this.CurrentPatient); this.FormUrl = StaticFormMap.FormUrl; }
private LocalArea CreateLocalArea(ServiceArea serviceArea, string name) { LocalArea result = new LocalArea(); var request = new HttpRequestMessage(HttpMethod.Post, "/api/localareas"); result.Name = name; result.ServiceArea = serviceArea; string jsonString = result.ToJson(); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); Task <HttpResponseMessage> responseTask = _client.SendAsync(request); responseTask.Wait(); HttpResponseMessage response = responseTask.Result; response.EnsureSuccessStatusCode(); Task <string> stringTask = response.Content.ReadAsStringAsync(); stringTask.Wait(); // parse as JSON. jsonString = stringTask.Result; result = JsonConvert.DeserializeObject <LocalArea>(jsonString); return(result); }
/// <summary> /// Copy from legacy to new record /// </summary> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="serviceArea"></param> static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.Service_Area oldObject, ref ServiceArea serviceArea, string systemId) { bool isNew = false; if (serviceArea == null) { isNew = true; serviceArea = new ServiceArea(); } if (oldObject.Service_Area_Id <= 0) { return; } serviceArea.Id = oldObject.Service_Area_Id; serviceArea.MinistryServiceAreaID = oldObject.Service_Area_Id; serviceArea.DistrictId = oldObject.District_Area_Id; serviceArea.Name = oldObject.Service_Area_Desc.Trim(); serviceArea.AreaNumber = oldObject.Service_Area_Cd; District district = dbContext.Districts.FirstOrDefault(x => x.MinistryDistrictID == oldObject.District_Area_Id); if (district == null) // This means that the District is not in the database. { // This happens when the production data does not include district Other than "Lower Mainland" or all the districts return; } serviceArea.District = district; try { serviceArea.StartDate = DateTime.ParseExact(oldObject.FiscalStart.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); } catch (Exception e) { string str = e.ToString(); } if (isNew) { serviceArea.CreateUserid = systemId; serviceArea.CreateTimestamp = DateTime.UtcNow; dbContext.ServiceAreas.Add(serviceArea); } else { serviceArea.LastUpdateUserid = systemId; serviceArea.LastUpdateTimestamp = DateTime.UtcNow; dbContext.ServiceAreas.Update(serviceArea); } try { int iResult = dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("*** ERROR With add or update Service Area ***"); performContext.WriteLine(e.ToString()); } }
/// <summary> /// Returns a service area for a given Ministry Id /// </summary> /// <param name="context"></param> /// <param name="id">The Ministry Id</param> /// <returns>Region</returns> public static ServiceArea GetServiceAreaByMinistryServiceAreaId(this IDbAppContext context, int id) { ServiceArea serviceArea = context.ServiceAreas.Where(x => x.MinistryServiceAreaID == id) .Include(x => x.District.Region) .FirstOrDefault(); return(serviceArea); }
public ActionResult DeleteConfirmed(int id) { ServiceArea serviceArea = db.ServiceAreas.Find(id); db.ServiceAreas.Remove(serviceArea); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Creates a new school bus /// </summary> /// <remarks>The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request. The field value consists of a single absolute URI. </remarks> /// <param name="item"></param> /// <response code="201">SchoolBus created</response> public virtual IActionResult AddBusAsync(SchoolBus item) { // adjust school bus owner if (item.SchoolBusOwner != null) { int school_bus_owner_id = item.SchoolBusOwner.Id; bool school_bus_owner_exists = _context.SchoolBusOwners.Any(a => a.Id == school_bus_owner_id); if (school_bus_owner_exists) { SchoolBusOwner school_bus_owner = _context.SchoolBusOwners.First(a => a.Id == school_bus_owner_id); item.SchoolBusOwner = school_bus_owner; } } // adjust service area. if (item.ServiceArea != null) { int service_area_id = item.ServiceArea.Id; bool service_area_exists = _context.ServiceAreas.Any(a => a.Id == service_area_id); if (service_area_exists) { ServiceArea service_area = _context.ServiceAreas.First(a => a.Id == service_area_id); item.ServiceArea = service_area; } } // adjust school district if (item.SchoolBusDistrict != null) { int schoolbus_district_id = item.SchoolBusDistrict.Id; bool schoolbus_district_exists = _context.SchoolDistricts.Any(a => a.Id == schoolbus_district_id); if (schoolbus_district_exists) { SchoolDistrict school_district = _context.SchoolDistricts.First(a => a.Id == schoolbus_district_id); item.SchoolBusDistrict = school_district; } } // adjust home city if (item.HomeTerminalCity != null) { int city_id = item.HomeTerminalCity.Id; bool city_exists = _context.Cities.Any(a => a.Id == city_id); if (city_exists) { City city = _context.Cities.First(a => a.Id == city_id); item.HomeTerminalCity = city; } } _context.SchoolBuss.Add(item); _context.SaveChanges(); return(new ObjectResult(item)); }
PatientService() { CurrentPatient = null; CurrentServiceArea = null; Formset = null; // Enrollment = null; FormUrl = StaticFormMap.FormUrl; }
public ActionResult Edit([Bind(Include = "Id,Name,Address,Description")] ServiceArea serviceArea) { if (ModelState.IsValid) { db.Entry(serviceArea).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(serviceArea)); }
public ActionResult Create([Bind(Include = "Id,Name,Address,Description")] ServiceArea serviceArea) { if (ModelState.IsValid) { db.ServiceAreas.Add(serviceArea); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(serviceArea)); }
public int GetServiceAreaById(string name) { try { ServiceArea sv = mgr.GetServiceArea(name); return(sv.Id); } catch (Exception e) { throw new Exception(e.Message); } }
private void DeleteServiceArea(ServiceArea serviceArea) { var request = new HttpRequestMessage(HttpMethod.Post, "/api/serviceareas/" + serviceArea.Id + "/delete"); Task <HttpResponseMessage> responseTask = _client.SendAsync(request); responseTask.Wait(); HttpResponseMessage response = responseTask.Result; response.EnsureSuccessStatusCode(); }
/// <summary> /// Integration test for Serviceareas /// </summary> public async void TestServiceareas() { // first test the POST. var request = new HttpRequestMessage(HttpMethod.Post, "/api/serviceareas"); // create a new object. ServiceArea servicearea = new ServiceArea(); string jsonString = servicearea.ToJson(); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); servicearea = JsonConvert.DeserializeObject <ServiceArea>(jsonString); // get the id var id = servicearea.Id; // now do an update. request = new HttpRequestMessage(HttpMethod.Put, "/api/serviceareas/" + id); request.Content = new StringContent(servicearea.ToJson(), Encoding.UTF8, "application/json"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // do a get. request = new HttpRequestMessage(HttpMethod.Get, "/api/serviceareas/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); servicearea = JsonConvert.DeserializeObject <ServiceArea>(jsonString); // do a delete. request = new HttpRequestMessage(HttpMethod.Post, "/api/serviceareas/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/serviceareas/" + id); response = await _client.SendAsync(request); Assert.Equal(response.StatusCode, HttpStatusCode.NotFound); }
public IHttpActionResult GetServiceAreasList([FromBody] ServiceArea serviceArea) { List <ServiceArea> serviceAreaList = serviceAreaRepositoryObj.GetServiceAreas().ToList(); try { return(Ok(serviceAreaList)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult DeleteServiceArea([FromBody] int Id) { ServiceArea serviceAreaList = serviceAreaRepositoryObj.DeleteServiceAreas(Id); serviceAreaRepositoryObj.Save(); try { return(Ok("Service Area deleted successfully")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult InsertServiceAreaToList([FromBody] ServiceArea serviceArea) { ServiceArea serviceAreaList = serviceAreaRepositoryObj.InsertServiceArea(serviceArea); eventTypesRepositoryObj.Save(); try { return(Ok("Service Area Added Successfully")); } catch (Exception e) { return(BadRequest(e.Message)); } }
// GET: ServiceAreas/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceArea serviceArea = db.ServiceAreas.Find(id); if (serviceArea == null) { return(HttpNotFound()); } return(View(serviceArea)); }
public IHttpActionResult InsertServiceAreas([FromBody] ServiceArea serviceArea) { ServiceArea addServiceArea = serviceAreaRepositoryObj.InsertServiceArea(serviceArea); serviceAreaRepositoryObj.Save(); try { return(Ok("serviceArea inserted successfully")); } catch (Exception e) { return(BadRequest(e.Message)); } }
/// <summary> /// /// </summary> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="localArea"></param> static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.Area oldObject, ref LocalArea localArea, string systemId) { bool isNew = false; if (oldObject.Area_Id <= 0) { return; } if (localArea == null) { isNew = true; localArea = new LocalArea(); localArea.Id = oldObject.Area_Id; } try { localArea.Name = oldObject.Area_Desc.Trim(); } catch (Exception e) { string istr = e.ToString(); } try { ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.MinistryServiceAreaID == oldObject.Service_Area_Id); localArea.ServiceArea = serviceArea; } catch (Exception e) { string iStr = e.ToString(); } if (isNew) { localArea.CreateUserid = systemId; localArea.CreateTimestamp = DateTime.UtcNow; dbContext.LocalAreas.Add(localArea); } else { localArea.LastUpdateUserid = systemId; localArea.LastUpdateTimestamp = DateTime.UtcNow; dbContext.LocalAreas.Update(localArea); } }
/// <summary> /// /// </summary> /// <remarks>Updates a Service Area</remarks> /// <param name="id">id of Service Area to update</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">Service Area not found</response> public virtual IActionResult ServiceareasIdPutAsync(int id, ServiceArea body) { var exists = _context.ServiceAreas.Any(a => a.Id == id); if (exists && id == body.Id) { _context.ServiceAreas.Update(body); // Save the changes _context.SaveChanges(); return(new ObjectResult(body)); } else { // record not found return(new StatusCodeResult(404)); } }
/// <summary> /// Get service area by id /// </summary> /// <remarks>Returns a specific Service Area</remarks> /// <param name="id">id of Service Area to fetch</param> /// <response code="200">OK</response> public virtual IActionResult ServiceAreasIdGetAsync(int id) { bool exists = _context.ServiceAreas.Any(a => a.Id == id); if (exists) { ServiceArea result = _context.ServiceAreas .Where(a => a.Id == id) .Include(a => a.District.Region) .FirstOrDefault(); return(new ObjectResult(result)); } // record not found return(new StatusCodeResult(404)); }
/// <summary> /// Update service area /// </summary> /// <remarks>Updates a Service Area</remarks> /// <param name="id">id of Service Area to update</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">Service Area not found</response> public virtual IActionResult ServiceAreasIdPutAsync(int id, ServiceArea item) { bool exists = _context.ServiceAreas.Any(a => a.Id == id); if (exists && id == item.Id) { AdjustRecord(item); _context.ServiceAreas.Update(item); // Save the changes _context.SaveChanges(); return(new ObjectResult(item)); } // record not found return(new StatusCodeResult(404)); }
/// <summary> /// Get service area by id /// </summary> /// <remarks>Returns a specific Service Area</remarks> /// <param name="id">id of Service Area to fetch</param> /// <response code="200">OK</response> public virtual IActionResult ServiceAreasIdGetAsync(int id) { bool exists = _context.ServiceAreas.Any(a => a.Id == id); if (exists) { ServiceArea result = _context.ServiceAreas .Where(a => a.Id == id) .Include(a => a.District.Region) .FirstOrDefault(); return(new ObjectResult(new HetsResponse(result))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// Update service area /// </summary> /// <remarks>Updates a Service Area</remarks> /// <param name="id">id of Service Area to update</param> /// <param name="item"></param> /// <response code="200">OK</response> /// <response code="404">Service Area not found</response> public virtual IActionResult ServiceAreasIdPutAsync(int id, ServiceArea item) { bool exists = _context.ServiceAreas.Any(a => a.Id == id); if (exists && id == item.Id) { AdjustRecord(item); _context.ServiceAreas.Update(item); // save the changes _context.SaveChanges(); return(new ObjectResult(new HetsResponse(item))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }
/// <summary> /// Copy xml item to instance (table entries) /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="instance"></param> /// <param name="systemId"></param> static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.EquipType oldObject, ref Models.DistrictEquipmentType instance, string systemId) { bool isNew = false; if (oldObject.Equip_Type_Id <= 0) { return; } //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId); Models.User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId); if (instance == null) { isNew = true; instance = new Models.DistrictEquipmentType(); instance.Id = oldObject.Equip_Type_Id; try //Combining <Equip_Type_Cd> and < Equip_Type_Desc> together { instance.DistrictEquipmentName = oldObject.Equip_Type_Cd.Length >= 10 ? oldObject.Equip_Type_Cd.Substring(0, 10) : oldObject.Equip_Type_Cd + "-" + (oldObject.Equip_Type_Desc.Length >= 210 ? oldObject.Equip_Type_Desc.Substring(0, 210) : oldObject.Equip_Type_Desc); // instance.DistrictEquipmentName = oldObject.ToDelimString(" | "); } catch { } ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.MinistryServiceAreaID == oldObject.Service_Area_Id); if (serviceArea != null) { int districtId = serviceArea.DistrictId ?? 0; District dis = dbContext.Districts.FirstOrDefault(x => x.RegionId == districtId); instance.DistrictId = districtId; instance.District = dis; } // instance.EquipmentType = instance.CreateTimestamp = DateTime.UtcNow; instance.CreateUserid = createdBy.SmUserId; dbContext.DistrictEquipmentTypes.Add(instance); } }
public SearchIndexServiceAreaMappingAttribute(ServiceArea relatedArea) { RelatedArea = relatedArea; }