public ActionResult Create(WebsiteServiceProvider provider) { try { if (!ModelState.IsValid) { this.ResetForInvalidModel(provider); this.SetErrorMessage(); return(this.View(provider)); } // In each location, don't create a location contact if no information is given. foreach (var curLocation in provider.Locations) { curLocation.StateId = int.Parse(curLocation.StateIdString); if (this.IsContactPersonEmpty(curLocation.ContactPerson)) { curLocation.ContactPerson = null; } } var webToDb = new WebToDatabaseServiceProvider(); provider.State = ObjectStatus.ObjectState.Create; // Need an empty service areas object if no service areas were included. if (provider.Services == null) { provider.Services = new WebServiceAreas(); } webToDb.UpdateServiceProvider(provider, this.UserId); this.TempData["Info"] = string.Format("The provider {0} was created succesfully.", provider.Name); return(this.RedirectToAction("Index")); } catch (Exception ex) { this.SetupViewBag(); this.SetupLocationStateDropdown(provider); foreach (var curLocation in provider.Locations.Where(curLocation => curLocation.Coverage == null)) { curLocation.Coverage = new List <Coverage>(); } this.TempData["Error"] = "An error occured while saving the service provider."; return(this.View(provider)); } }
public ActionResult Delete(int id) { var provider = this.dataLogics.GetServiceProviderById(id); provider.State = ObjectStatus.ObjectState.Delete; var webToDb = new WebToDatabaseServiceProvider(); if (!webToDb.UpdateServiceProvider(provider, this.UserId)) { this.TempData["Error"] = "An error occured while deleting the service provider."; } else { this.TempData["Info"] = "The provider was deleted succesfully."; } return(this.RedirectToAction("Index")); }
public ActionResult Edit(WebsiteServiceProvider provider) { try { if (!ModelState.IsValid) { this.ResetForInvalidModel(provider); this.SetErrorMessage(); return(this.View(provider)); } var original = this.dataLogics.GetServiceProviderById(provider.Id); if (provider.Services == null) { provider.Services = new WebServiceAreas { State = ObjectStatus.ObjectState.Update, ServiceAreas = new List <int>() }; } // Check against original locations to see which are new, and what has been removed. this.SetStateFlagsLocations(provider, original); provider.State = ObjectStatus.ObjectState.Update; var webToDb = new WebToDatabaseServiceProvider(); webToDb.UpdateServiceProvider(provider, this.UserId); this.TempData["Info"] = string.Format("The provider {0} was updated succesfully.", provider.Name); if (User.IsInRole("1")) { return(this.RedirectToAction("Index")); } return(this.RedirectToAction("Details", new { id = provider.Id })); } catch (Exception ex) { return(this.View()); } }
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 }; }