/// <summary> /// The update location. /// </summary> /// <param name="serviceLocation"> /// The service location. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool UpdateLocation(ServiceProviderLocation serviceLocation) { try { var location = this.db.Locations.Single(l => l.ID == serviceLocation.Id); location.Street = serviceLocation.Street; location.City = serviceLocation.City; location.StateID = serviceLocation.StateId; location.Zip = serviceLocation.Zip; location.CountryID = serviceLocation.CountryId; location.Display = serviceLocation.Display; location.Name = serviceLocation.Name; if (serviceLocation.ContactPerson != null) { location.ContactPersonID = serviceLocation.ContactPerson.Id; } else { location.ContactPersonID = null; } this.db.Entry(location).State = EntityState.Modified; this.db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public void MyTestInitialize() { this.controller = new ServiceProviderController(); this.originalLocation = new ServiceProviderLocation { Id = 1, StateIdString = "34", Contact = new ServiceProviderContactRequired { Id = 1223 }, Coverage = new List <Coverage> { new Coverage { CountyId = 1, CountryId = 1, Id = 2, StateId = 1 } } }; this.originalProvider = new WebsiteServiceProvider { Id = 4, Name = "Test", Type = 2, Locations = new List <ServiceProviderLocation> { this.originalLocation } }; }
/// <summary> /// Delete a location. /// </summary> /// <param name="location"> /// The location. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool DeleteLocation(ServiceProviderLocation location) { if (location.ContactPerson != null) { if (!this.serviceProviderRepo.DeleteContact(this.ConvertServiceProviderContactToContact(location.ContactPerson.Contact))) { return(false); } if (!this.serviceProviderRepo.DeleteContactPerson(location.ContactPerson)) { return(false); } } if (!this.serviceProviderRepo.DeleteContact(this.ConvertServiceProviderContactToContact(location.Contact))) { return(false); } if (!this.serviceProviderRepo.DeleteAllCoveragesForLocation(location.Id)) { return(false); } return(this.serviceProviderRepo.DeleteLocation(location.Id)); }
/// <summary> /// The set state flags for coverage in a location. /// </summary> /// <param name="location"> The updated location. </param> /// <param name="original"> The original location. </param> private void SetStateFlagsCoverages(ServiceProviderLocation location, ServiceProviderLocation original) { // Set all the existing coverages to be updated. foreach (var curCoverage in location.Coverage) { curCoverage.State = curCoverage.Id == 0 ? ObjectStatus.ObjectState.Create : ObjectStatus.ObjectState.Update; } // Get the deleted items and set them to be deleted var deletedItems = new List <Coverage>(); var deletedList = from coverage in original.Coverage let found = location.Coverage.Find(x => x.Id == coverage.Id) let hasBeenDeleted = found == null where hasBeenDeleted select coverage; foreach (var curLocation in deletedList) { curLocation.State = ObjectStatus.ObjectState.Delete; deletedItems.Add(curLocation); } if (deletedItems.Count > 0) { location.Coverage.AddRange(deletedItems); } }
/// <summary> /// The create location. /// </summary> /// <param name="location"> /// The location. /// </param> /// <returns> /// The <see cref="ServiceProviderLocation"/>. /// </returns> private ServiceProviderLocation CreateLocation(Location location) { var contact = this.CreateLocationContact(location.Contact); var contactPerson = this.CreateServiceProviderContactPerson(location.ContactPerson); var coverage = this.CreateCoverage(location); var serviceLocation = new ServiceProviderLocation { Name = location.Name, City = location.City, Contact = contact, ContactPerson = contactPerson, CountryId = location.CountryID, Coverage = coverage, Display = location.Display, Id = location.ID, State = ObjectStatus.ObjectState.Read, StateId = location.StateID, StateIdString = location.State.Abbreviation, Street = location.Street, Zip = location.Zip }; return(serviceLocation); }
public ActionResult DeleteConfirmed(int id) { ServiceProviderLocation serviceProviderLocation = db.ServiceProviderLocations.Find(id); db.ServiceProviderLocations.Remove(serviceProviderLocation); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult GetServiceProviderLocation(int id) { ServiceProviderLocation serviceProviderLocation = db.ServiceProviderLocations.Find(id); if (serviceProviderLocation == null) { return(NotFound()); } return(Ok(serviceProviderLocation)); }
public ActionResult Edit([Bind(Include = "ServiceProviderLocationID,ServiceProviderID,ServiceProviderLatitude,ServiceProviderLongitude")] ServiceProviderLocation serviceProviderLocation) { if (ModelState.IsValid) { db.Entry(serviceProviderLocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } //ViewBag.DestinationID = new SelectList(db.Destinations, "DestinationID", "DestinationName", serviceProviderLocation.DestinationID); ViewBag.ServiceProviderID = new SelectList(db.ServiceProviders, "ServiceProviderID", "ServiceProviderName", serviceProviderLocation.ServiceProviderID); return(View(serviceProviderLocation)); }
// GET: ServiceProviderLocations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceProviderLocation serviceProviderLocation = db.ServiceProviderLocations.Find(id); if (serviceProviderLocation == null) { return(HttpNotFound()); } return(View(serviceProviderLocation)); }
public void EditProviderLocationAddCoverageTest() { using (ShimsContext.Create()) { var updatedLocation1 = new ServiceProviderLocation { Id = 1, StateIdString = "34", Contact = new ServiceProviderContactRequired { Id = 1223 }, ContactPerson = new ServiceProviderContactPerson { Id = 0 }, Coverage = new List <Coverage> { new Coverage { CountyId = 1, CountryId = 1, Id = 2, StateId = 1 }, new Coverage { CountyId = 5, CountryId = 1, Id = 0, StateId = 1 } } }; var updatedProvider = new WebsiteServiceProvider { Id = 4, Name = "Test2", Type = 2, Locations = new List <ServiceProviderLocation> { updatedLocation1 } }; ShimDataLogics.AllInstances.GetServiceProviderByIdInt32 = (access, id) => this.originalProvider; ShimWebToDatabaseServiceProvider.AllInstances.UpdateServiceProviderWebsiteServiceProviderInt32 = (provider, serviceProvider, userId) => true; var result = this.controller.Edit(updatedProvider); Assert.AreEqual(ObjectStatus.ObjectState.Update, updatedProvider.State); Assert.AreEqual(ObjectStatus.ObjectState.Update, updatedProvider.Locations[0].Coverage[0].State); Assert.AreEqual(ObjectStatus.ObjectState.Create, updatedProvider.Locations[0].Coverage[1].State); } }
// GET: ServiceProviderLocations/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceProviderLocation serviceProviderLocation = db.ServiceProviderLocations.Find(id); if (serviceProviderLocation == null) { return(HttpNotFound()); } //ViewBag.DestinationID = new SelectList(db.Destinations.OrderBy(d => d.DestinationName), "DestinationID", "DestinationName", serviceProviderLocation.DestinationID); ViewBag.ServiceProviderID = new SelectList(db.ServiceProviders.OrderBy(d => d.ServiceProviderName), "ServiceProviderID", "ServiceProviderName", serviceProviderLocation.ServiceProviderID); return(View(serviceProviderLocation)); }
/// <summary> /// The convert location. /// </summary> /// <param name="location"> /// The location. /// </param> /// <param name="providerId"> /// The provider id. /// </param> /// <param name="locationContactId"> /// The location contact id. /// </param> /// <returns> /// The <see cref="Location"/>. /// </returns> private Location ConvertLocation(ServiceProviderLocation location, int providerId, int locationContactId) { var newLocation = new Location { Name = location.Name, City = location.City, CountryID = location.CountryId, StateID = location.StateId, Street = location.Street, Zip = location.Zip, ProviderID = providerId, Display = location.Display, ContactID = locationContactId }; return(newLocation); }
/// <summary> /// Checks the contact person. /// </summary> /// <param name="contactPerson"> /// The contact person. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool CheckContactPerson(ServiceProviderLocation location) { bool response; var contactPerson = location.ContactPerson; switch (location.ContactPerson.State) { case ObjectStatus.ObjectState.Create: var contactPersonContactId = this.CreateContactId(this.ConvertServiceProviderContactToContact(contactPerson.Contact)); var contactPersonId = this.CreateContactPerson(contactPerson, contactPersonContactId); location.ContactPerson.Id = contactPersonId; return(true); break; case ObjectStatus.ObjectState.Update: response = this.serviceProviderRepo.UpdateContactPerson(contactPerson); break; case ObjectStatus.ObjectState.Delete: var contact = contactPerson.Contact; response = this.serviceProviderRepo.DeleteContactPerson(contactPerson) && this.serviceProviderRepo.DeleteContact(this.ConvertServiceProviderContactToContact(contact)); return(response); case ObjectStatus.ObjectState.Read: response = true; break; default: response = false; break; } if (!response) { return(false); } response = this.CheckContact(contactPerson.Contact); return(response); }
/// <summary> /// The create location. /// </summary> /// <param name="location"> /// The location. /// </param> /// <param name="providerId"> /// The provider id. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool CreateLocation(ServiceProviderLocation location, int providerId) { // Create Contact for Location. var locationContactId = this.CreateContactId(this.ConvertServiceProviderContactToContact(location.Contact)); if (locationContactId == 0) { return(false); } // Convert to database Location var databaseLocation = this.ConvertLocation(location, providerId, locationContactId); // Create contact person and their contact information if not null if (location.ContactPerson != null) { var contactPersonContactId = this.CreateContactId(this.ConvertServiceProviderContactToContact(location.ContactPerson.Contact)); var contactPersonId = this.CreateContactPerson(location.ContactPerson, contactPersonContactId); databaseLocation.ContactPersonID = contactPersonId; } var locationId = this.CreateDatabaseLocation(databaseLocation); foreach (var area in location.Coverage) { // Create a database coverage area var success = this.CreateServiceArea(area.CountyId, locationId); if (!success) { return(false); } } return(true); }
public void EditProviderRemoveLocationTest() { using (ShimsContext.Create()) { var originalLocation2 = new ServiceProviderLocation { Id = 0, Contact = new ServiceProviderContactRequired { Id = 0 }, ContactPerson = new ServiceProviderContactPerson { Id = 0 }, Coverage = new List <Coverage> { new Coverage { CountyId = 4, CountryId = 1, Id = 2, StateId = 1 } } }; this.originalProvider.Locations.Add(originalLocation2); var updatedLocation = new ServiceProviderLocation { Id = 1, StateIdString = "34", Coverage = new List <Coverage> { new Coverage { CountyId = 1, CountryId = 1, Id = 2, StateId = 1 } }, Contact = new ServiceProviderContactRequired { Id = 2123, Email = "*****@*****.**" }, ContactPerson = new ServiceProviderContactPerson { FistName = "asdfas", LastName = "q234asdf", Contact = new ServiceProviderContact { Id = 1, Email = "*****@*****.**" } } }; var updatedProvider = new WebsiteServiceProvider { Id = 4, Name = "Test2", Type = 2, Locations = new List <ServiceProviderLocation> { updatedLocation } }; ShimDataLogics.AllInstances.GetServiceProviderByIdInt32 = (access, id) => this.originalProvider; ShimWebToDatabaseServiceProvider.AllInstances.UpdateServiceProviderWebsiteServiceProviderInt32 = (provider, serviceProvider, userId) => true; var result = this.controller.Edit(updatedProvider); Assert.AreEqual(ObjectStatus.ObjectState.Update, updatedProvider.State); Assert.AreEqual(ObjectStatus.ObjectState.Update, updatedProvider.Locations[0].State); Assert.AreEqual(ObjectStatus.ObjectState.Delete, updatedProvider.Locations[1].State); } }
public void MyTestInitialize() { this.target = new WebToDatabaseServiceProvider(); this.state = new State { Abbreviation = "OH", CountryID = 1, FullName = "Ohio", ID = 1 }; this.country = new Country { Abbreviation = "USA", ID = 1, FullName = "United States of America" }; this.county = new County { ID = 1, Name = "test county", StateId = 1, State = this.state }; this.contact = new ServiceProviderContact { Email = "*****@*****.**", Id = 1, Website = "www.test.org", PhoneNumber = "9373608284", HelpLine = "9373608888", State = ObjectStatus.ObjectState.Update }; this.locationContact = new ServiceProviderContactRequired { Email = "*****@*****.**", Id = 1, Website = "www.test.org", PhoneNumber = "9373608284", HelpLine = "9373608888", State = ObjectStatus.ObjectState.Update }; this.contactPerson = new ServiceProviderContactPerson { Id = 1, Contact = this.contact, FistName = "test", LastName = "user", JobTitle = "Tester", State = ObjectStatus.ObjectState.Update }; this.coverage1 = new Coverage { CountryId = 1, CountryName = "USA", CountyId = 1, CountyName = "Clark", Id = 1, State = ObjectStatus.ObjectState.Update, StateId = 1, StateName = "Ohio" }; this.coverage2 = new Coverage { CountryId = 1, CountryName = "USA", CountyId = 2, CountyName = "Clark 2", Id = 1, State = ObjectStatus.ObjectState.Update, StateId = 1, StateName = "Ohio" }; this.coverageList = new List <Coverage> { this.coverage1, this.coverage2 }; this.location1 = new ServiceProviderLocation { Name = "Location1", Coverage = this.coverageList, CountryId = 1, Contact = this.locationContact, ContactPerson = this.contactPerson, City = "testville 1", Id = 1, Display = true, Zip = "45344", Street = "Test way 1", StateId = this.state.ID, State = ObjectStatus.ObjectState.Update }; this.location2 = new ServiceProviderLocation { Name = "Location2", Coverage = this.coverageList, CountryId = 1, Contact = this.locationContact, City = "testville 2", Id = 2, Display = true, Zip = "45344", Street = "Test way 2", StateId = this.state.ID, State = ObjectStatus.ObjectState.Update }; this.locations = new List <ServiceProviderLocation> { this.location1, this.location2 }; this.webServiceAreas = new WebServiceAreas { ServiceAreas = new List <int> { 1, 2, 3 }, State = ObjectStatus.ObjectState.Update }; this.websiteServiceProvider = new WebsiteServiceProvider { Locations = this.locations, Services = this.webServiceAreas, Description = "Test Web Provider", DisplayRank = 1, Id = 1, Name = "test provider 1", Type = 1, IsActive = true, State = ObjectStatus.ObjectState.Update }; }