public ActionResult UpdateEmptyLatLong(int[] companyId) { GeoLocator locator = new GeoLocator(); CompanyProfile company; try { for (int i = 0; i < companyId.Length; i++) { company = _service.Get(companyId[i]); if (company.Id != 1) { if (company.Address1 == null && company.City == null && company.StateId != null && company.PostalCode != null) { company.GeoLocation = locator.GetFromStateZip(company.State.Abbr, company.PostalCode); _service.Update(company); } else if ((company.Address1 == null || company.Address1 == string.Empty) && company.StateId != null && company.PostalCode != null) { company.GeoLocation = locator.GetFromCityStateZip(company.City, company.State.Abbr, company.PostalCode); _service.Update(company); } else if ((company.Address1 != null && company.Address1 != string.Empty) && (company.City != null && company.City != string.Empty) && company.StateId != null && company.PostalCode != null) { company.GeoLocation = locator.GetFromAddress(company.Address1, company.City, company.State.Abbr, company.PostalCode); _service.Update(company); } } } return RedirectToAction("Index"); } catch (Exception ex) { throw new HttpException(500, ex.Message); } }
public ActionResult Edit(EditCompanyViewModel viewModel) { if (ModelState.IsValid) { // get company int userId = _security.GetUserId(User.Identity.Name); var company = _serviceLayer.GetUserProfiles(u => u.UserId == userId).FirstOrDefault().Company; if (viewModel.Address1 != null) company.Address1 = viewModel.Address1.Trim(); if (viewModel.Address2 != null) company.Address2 = viewModel.Address2.Trim(); company.City = viewModel.City; company.CompanyName = viewModel.CompanyName.Trim(); company.OperatingDistance = viewModel.OperatingDistance; company.Phone = Util.ConvertPhoneForStorage(viewModel.Phone.Trim()); company.PostalCode = viewModel.PostalCode.Trim(); //company.StateId = viewModel.StateId; company.State = _serviceLayer.GetState(viewModel.StateId.Value); GeoLocator locator = new GeoLocator(); if (company.Address1 == null && company.City == null && company.StateId != null && company.PostalCode != null) { company.GeoLocation = locator.GetFromStateZip(company.State.Abbr, company.PostalCode); } else if ((company.Address1 == null || company.Address1 == string.Empty) && company.StateId != null && company.PostalCode != null) { company.GeoLocation = locator.GetFromCityStateZip(company.City, company.State.Abbr, company.PostalCode); } else if ((company.Address1 != null && company.Address1 != string.Empty) && (company.City != null && company.City != string.Empty) && company.StateId != null && company.PostalCode != null) { company.GeoLocation = locator.GetFromAddress(company.Address1, company.City, company.State.Abbr, company.PostalCode); } // did business type change? if (company.BusinessType != viewModel.BusinessType) { // add new role for all users in company switch (viewModel.BusinessType.Value) { case BusinessType.GeneralContractor: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "general_contractor"); break; case BusinessType.SubContractor: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "subcontractor"); break; case BusinessType.Architect: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "architect"); break; case BusinessType.Engineer: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "engineer"); break; case BusinessType.Owner: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "owner_client"); break; case BusinessType.MaterialsVendor: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "materials_vendor"); break; case BusinessType.MaterialsMfg: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "materials_manufacturer"); break; case BusinessType.Consultant: _security.AddUsersToRole(company.Users.Select(x => x.Email).ToArray(), "consultant"); break; }; // remove old role for all users in company switch (company.BusinessType) { case BusinessType.GeneralContractor: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "general_contractor"); break; case BusinessType.SubContractor: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "subcontractor"); break; case BusinessType.Architect: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "architect"); break; case BusinessType.Engineer: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "engineer"); break; case BusinessType.Owner: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "owner_client"); break; case BusinessType.MaterialsVendor: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "materials_vendor"); break; case BusinessType.MaterialsMfg: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "materials_manufacturer"); break; case BusinessType.Consultant: _security.RemoveUsersFromRole(company.Users.Select(x => x.Email).ToArray(), "consultant"); break; }; // update company business type company.BusinessType = viewModel.BusinessType.Value; } // update changes in the database if (_serviceLayer.Update(company)) { return RedirectToRoute("Default", new { controller = "Account", action = "Manage", message = ManageMessageId.ChangeCompanyInfoSuccess }); } else { Util.MapValidationErrors(_serviceLayer.ValidationDic, this.ModelState); viewModel.States = _serviceLayer.GetStates().Select(x => new SelectListItem { Text = x.Abbr, Value = x.Id.ToString(), Selected = x.Id == viewModel.StateId }); //viewModel.BusinessTypes = _serviceLayer.GetBusinessTypes().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == viewModel.BusinessTypeId }); return View(viewModel); } } else { viewModel.States = _serviceLayer.GetStates().Select(x => new SelectListItem { Text = x.Abbr, Value = x.Id.ToString(), Selected = x.Id == viewModel.StateId }); //viewModel.BusinessTypes = _serviceLayer.GetBusinessTypes().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == viewModel.BusinessTypeId }); return View(viewModel); } }
public ActionResult UpdateEmptyLatLong(int[] projectId) { GeoLocator locator = new GeoLocator(); BCModel.Projects.Project theProject; for (int i = 0; i < projectId.Length; i++) { theProject = _service.Get(projectId[i]); if (theProject.Address == null && theProject.City == null && theProject.StateId != null && theProject.PostalCode != null) { theProject.GeoLocation = locator.GetFromStateZip(theProject.State.Abbr, theProject.PostalCode); _service.Update(theProject); } else if ((theProject.Address == null || theProject.Address == string.Empty) && theProject.StateId != null && theProject.PostalCode != null) { theProject.GeoLocation = locator.GetFromCityStateZip(theProject.City, theProject.State.Abbr, theProject.PostalCode); _service.Update(theProject); } else if ((theProject.Address != null && theProject.Address != string.Empty) && (theProject.City != null && theProject.City != string.Empty) && theProject.StateId != null && theProject.PostalCode != null) { theProject.GeoLocation = locator.GetFromAddress(theProject.Address, theProject.City, theProject.State.Abbr, theProject.PostalCode); _service.Update(theProject); } } return RedirectToAction("Index"); }
public ActionResult Create(BCWeb.Areas.Admin.Models.Projects.ViewModel.ProjectEditModel viewModel) { if (!viewModel.ProjectCategory.HasValue) ModelState.AddModelError("ProjectCategory", "Project Category is required"); if (!viewModel.ProjectType.HasValue) ModelState.AddModelError("ProjectType", "Project Type is required"); if (ModelState.IsValid) { BCModel.Projects.Project toCreate = new BCModel.Projects.Project { Address = viewModel.Address, ArchitectId = viewModel.ArchitectId, BidDateTime = viewModel.BidDateTime, BuildingTypeId = viewModel.BuildingTypeId, City = viewModel.City, ConstructionTypeId = viewModel.ConstructionTypeId, CreatedById = viewModel.CreatedById, Description = viewModel.Description, Number = viewModel.Number, PostalCode = viewModel.PostalCode, ProjectCategory = viewModel.ProjectCategory.Value, ProjectType = viewModel.ProjectType.Value, StateId = viewModel.StateId, Title = viewModel.Title, BidPackages = new List<BidPackage>(), Scopes = new List<ProjectXScope>(), WalkThruDateTime = viewModel.WalkThruDateTime, WalkThruStatus = viewModel.WalkThruStatus.Value }; GeoLocator locator = new GeoLocator(); State projectState = _service.GetState(viewModel.StateId); if (viewModel.Address == null && viewModel.City == null && viewModel.StateId != null && viewModel.PostalCode != null) { toCreate.GeoLocation = locator.GetFromStateZip(projectState.Abbr, viewModel.PostalCode); } else if ((viewModel.Address == null || viewModel.Address == string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null) { toCreate.GeoLocation = locator.GetFromCityStateZip(viewModel.City, projectState.Abbr, viewModel.PostalCode); } else if ((viewModel.Address != null && viewModel.Address != string.Empty) && (viewModel.City != null && viewModel.City != string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null) { toCreate.GeoLocation = locator.GetFromAddress(viewModel.Address, viewModel.City, projectState.Abbr, viewModel.PostalCode); } BidPackage projectPackage = new BidPackage { IsMaster = true, BidDateTime = toCreate.BidDateTime, Description = "Master Bid Package", CreatedById = viewModel.ArchitectId, Project = toCreate, Scopes = new List<BidPackageXScope>(), Invitees = new List<Invitation>() }; UserProfile createdBy = _service.GetUserProfile(viewModel.CreatedById); // if createdby is a GC, self-invite if (createdBy.Company.BusinessType == BusinessType.GeneralContractor) { projectPackage.Invitees.Add(new Invitation { BidPackage = projectPackage, SentToId = viewModel.CreatedById, SentDate = DateTime.Now, AcceptedDate = DateTime.Now, InvitationType = InvitationType.SentFromCreatedBy }); } // add bp to project toCreate.BidPackages.Add(projectPackage); // set selected scopes for bp and project for (int i = 0; i < viewModel.SelectedScope.Count(); i++) { toCreate.Scopes.Add(new ProjectXScope { Project = toCreate, ScopeId = viewModel.SelectedScope.ElementAt(i) }); projectPackage.Scopes.Add(new BidPackageXScope { BidPackage = projectPackage, ScopeId = viewModel.SelectedScope.ElementAt(i) }); } // add project to system if (_service.Create(toCreate)) { return RedirectToAction("Index"); } else { Util.MapValidationErrors(_service.ValidationDic, this.ModelState); } } rePopVieModel(viewModel); return View(); }
public ActionResult Edit(BCWeb.Areas.Admin.Models.Projects.ViewModel.ProjectEditModel viewModel) { BCModel.Projects.Project toUpdate = _service.Get(viewModel.Id); toUpdate.Address = viewModel.Address; toUpdate.ArchitectId = viewModel.ArchitectId; toUpdate.BidDateTime = viewModel.BidDateTime; toUpdate.BuildingTypeId = viewModel.BuildingTypeId; toUpdate.City = viewModel.City; toUpdate.ConstructionTypeId = viewModel.ConstructionTypeId; toUpdate.CreatedById = viewModel.CreatedById; toUpdate.Description = viewModel.Description; toUpdate.Number = viewModel.Number; toUpdate.PostalCode = viewModel.PostalCode; toUpdate.ProjectCategory = viewModel.ProjectCategory.Value; toUpdate.ProjectType = viewModel.ProjectType.Value; toUpdate.StateId = viewModel.StateId; toUpdate.Title = viewModel.Title; toUpdate.BidPackages = new List<BidPackage>(); toUpdate.Scopes = new List<ProjectXScope>(); toUpdate.WalkThruDateTime = viewModel.WalkThruDateTime; toUpdate.WalkThruStatus = viewModel.WalkThruStatus.Value; GeoLocator locator = new GeoLocator(); State projectState = _service.GetState(viewModel.StateId); if (viewModel.Address == null && viewModel.City == null && viewModel.StateId != null && viewModel.PostalCode != null) { toUpdate.GeoLocation = locator.GetFromStateZip(projectState.Abbr, viewModel.PostalCode); } else if ((viewModel.Address == null || viewModel.Address == string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null) { toUpdate.GeoLocation = locator.GetFromCityStateZip(viewModel.City, projectState.Abbr, viewModel.PostalCode); } else if ((viewModel.Address != null && viewModel.Address != string.Empty) && (viewModel.City != null && viewModel.City != string.Empty) && viewModel.StateId != null && viewModel.PostalCode != null) { toUpdate.GeoLocation = locator.GetFromAddress(viewModel.Address, viewModel.City, projectState.Abbr, viewModel.PostalCode); } try { if (_service.Update(toUpdate)) { return RedirectToAction("Details", new { id = toUpdate.Id }); } else { Util.MapValidationErrors(_service.ValidationDic, ModelState); } } catch (Exception ex) { ModelState.AddModelError("Exception", ex.Message); } rePopVieModel(viewModel); return View(viewModel); }