// // GET: /Business/InternalLocationIndex/5 public ActionResult InternalLocationIndex(Guid businesslocationid) { BusinessLocationDTO businessLocationDTO = GetBusinessLocation(businesslocationid); ViewBag.BusinessId = businessLocationDTO.BusinessId; ViewBag.BusinessLocationId = businessLocationDTO.Id; return(PartialView(businessLocationDTO.InternalLocations)); }
// GET: /Business/InternalLocationEdit/5 public ActionResult InternalLocationEdit(Guid businesslocationid, Guid id) { BusinessLocationDTO businessLocationDTO = GetBusinessLocation(businesslocationid); if (businessLocationDTO == null) { return(HttpNotFound()); } return(PartialView(businessLocationDTO.InternalLocations.FirstOrDefault(r => r.Id == id))); }
// GET: /Business/BusinessLocation/5 public ActionResult BusinessLocationDetails(Guid businesslocationid) { if (businesslocationid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BusinessLocationDTO businesslocationdto = GetBusinessLocation(businesslocationid); ViewBag.StatesList = WebUI.Common.Common.GetStates(); if (businesslocationdto == null) { return(HttpNotFound()); } return(View(businesslocationdto)); }
public HttpResponseMessage PutBusinessLocation(Guid businessLocationId, BusinessLocationDTO businessLocationDTO) { if (ClaimsAuthorization.CheckAccess("Put", "BusinessLocationId", businessLocationDTO.Id.ToString())) { if (ModelState.IsValid) { var busLocation = MapperFacade.MapperConfiguration.Map <BusinessLocationDTO, BusinessLocation>(businessLocationDTO, db.BusinessLocations.Single(l => l.Id == businessLocationId)); foreach (var intLocDTO in businessLocationDTO.InternalLocations) { if (!String.IsNullOrEmpty(intLocDTO.Name)) { if (intLocDTO.Id != Guid.Empty) { var intLocation = MapperFacade.MapperConfiguration.Map <InternalLocationDTO, InternalLocation>(intLocDTO, db.InternalLocations.Find(intLocDTO.Id)); if (intLocation.Name != intLocDTO.Name) { db.Entry(intLocation).State = EntityState.Modified; } } else { busLocation.InternalLocations.Add(new InternalLocation { Id = Guid.NewGuid(), Name = intLocDTO.Name, BusinessLocation = busLocation }); } } } db.Entry(busLocation).State = EntityState.Modified; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized)); } }
// // GET: /Business/BusinessLocationCreate public ActionResult BusinessLocationCreate(Guid businessid) { ViewBag.StatesList = WebUI.Common.Common.GetStates(); var business = this.GetBusiness(businessid); ViewBag.HasInternalLocations = business.HasMultiInternalLocations; ViewBag.BusinessName = business.Name; BusinessLocationDTO model = new BusinessLocationDTO(); model.BusinessId = businessid; model.InternalLocations = new List <InternalLocationDTO>(); model.InternalLocations.Add(new InternalLocationDTO { Name = "Default" }); return(PartialView(model)); }
public ActionResult CreateAddBusinessLocation(BusinessLocationDTO businessLocationDTO, bool addNext) { if (ModelState.IsValid) { using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { var response = httpClient.PostAsJsonAsync("/api/BusinessAPI/businesslocation", businessLocationDTO).Result; if (response.IsSuccessStatusCode) { CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + businessLocationDTO.BusinessId.ToString()); //Remove the stale business item from the cache var busLocId = Guid.Parse(JsonConvert.DeserializeObject <dynamic>(response.Content.ReadAsStringAsync().Result).ToString()); //If user selected to add next business location if (addNext) { return(RedirectToAction("RefreshToken", "Account", new { returnAction = "CreateAddBusinessLocation", returnController = "Business", urlParams = "businessId=" + businessLocationDTO.BusinessId.ToString() })); } else { return(RedirectToAction("RefreshToken", "Account", new { returnAction = "RoleCreate", returnController = "Business", urlParams = "businessId=" + businessLocationDTO.BusinessId.ToString() })); } } else { //If and error occurred add details to model error. var error = JsonConvert.DeserializeObject <System.Web.Http.HttpError>(response.Content.ReadAsStringAsync().Result); ModelState.AddModelError(String.Empty, error.Message); } } } ViewBag.StatesList = WebUI.Common.Common.GetStates(); BusinessDTO businessDTO = GetBusiness(businessLocationDTO.BusinessId); ViewBag.BusinessName = businessDTO.Name; ViewBag.HasInternalLocations = businessDTO.HasMultiInternalLocations; return(PartialView(businessLocationDTO)); }
// GET: /Business/BusinessLocation/Edit/5 public ActionResult BusinessLocationEdit(Guid businesslocationid) { if (businesslocationid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BusinessLocationDTO businessLocationDTO = GetBusinessLocation(businesslocationid); if (businessLocationDTO == null) { return(HttpNotFound()); } ViewBag.StatesList = WebUI.Common.Common.GetStates(); BusinessDTO businessDTO = GetBusiness(businessLocationDTO.BusinessId); ViewBag.BusinessName = businessDTO.Name; ViewBag.HasInternalLocations = businessDTO.HasMultiInternalLocations; return(PartialView(businessLocationDTO)); }
public ActionResult BusinessLocationCreate(BusinessLocationDTO businessLocationDTO) { if (ModelState.IsValid) { //Replace with updated location using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { var responseMessage = httpClient.PostAsJsonAsync("api/BusinessAPI/businesslocation", businessLocationDTO).Result; responseMessage.EnsureSuccessStatusCode(); CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + businessLocationDTO.BusinessId.ToString()); //Remove the stale business item from the cache return(RedirectToAction("RefreshToken", "Account", new { returnAction = "Details", returnController = "Business", urlParams = "Id=" + businessLocationDTO.BusinessId.ToString() })); } } else { ViewBag.BusinessId = businessLocationDTO.BusinessId; ViewBag.StatesList = WebUI.Common.Common.GetStates(); return(View(businessLocationDTO)); } }
public ActionResult CreateAddBusinessLocation(Guid businessId, bool?isNew) { BusinessDTO businessDTO = GetBusiness(businessId); var model = new BusinessLocationDTO { BusinessId = businessId }; model.InternalLocations = new List <InternalLocationDTO>(); model.InternalLocations.Add(new InternalLocationDTO { Name = "Default" }); ViewBag.BusinessName = businessDTO.Name; ViewBag.HasInternalLocations = businessDTO.HasMultiInternalLocations; ViewBag.IsNew = isNew.GetValueOrDefault(false); ViewBag.StatesList = WebUI.Common.Common.GetStates(); return(PartialView(model)); }
public ActionResult BusinessLocationEdit(BusinessLocationDTO businesslocationdto) { if (ModelState.IsValid) { //Replace with updated location using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { var responseMessage = httpClient.PutAsJsonAsync("api/BusinessAPI/businesslocation/" + businesslocationdto.Id.ToString(), businesslocationdto).Result; responseMessage.EnsureSuccessStatusCode(); //Invalidate cache items CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS_LOCATION + businesslocationdto.Id.ToString()); CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + businesslocationdto.BusinessId.ToString()); return(RedirectToAction("Details", new { id = businesslocationdto.BusinessId })); } } else { ViewBag.StatesList = WebUI.Common.Common.GetStates(); return(View(businesslocationdto)); } }
public HttpResponseMessage PostBusinessLocation(BusinessLocationDTO businessLocationDTO) { if (ClaimsAuthorization.CheckAccess("Put", "BusinessId", businessLocationDTO.BusinessId.ToString())) { if (ModelState.IsValid) { //Ensure this is not a duplicate location name var existingBusLoc = db.BusinessLocations.FirstOrDefault(bl => bl.Business.Id == businessLocationDTO.BusinessId && bl.Name == businessLocationDTO.Name); if (existingBusLoc != null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "A business location with this name already exists.")); } var buslocation = MapperFacade.MapperConfiguration.Map <BusinessLocationDTO, BusinessLocation>(businessLocationDTO); buslocation.Id = Guid.NewGuid(); //Assign new ID on save. buslocation.Business = db.Businesses.Find(businessLocationDTO.BusinessId); buslocation.Enabled = true; foreach (var intLoc in businessLocationDTO.InternalLocations) { if (!String.IsNullOrEmpty(intLoc.Name)) { buslocation.InternalLocations.Add(new InternalLocation { Id = Guid.NewGuid(), Name = intLoc.Name, BusinessLocation = buslocation }); } } //Need to create a default preferences object BusinessPreferences busPref = new BusinessPreferences { Id = Guid.NewGuid(), CancelShiftAllowed = true, CancelShiftTimeframe = 0, BusinessLocation = buslocation }; db.BusinessPreferences.Add(busPref); //New business will also have default employee who created as a manager var emp = new Employee(); var email = HttpContext.Current.User.Identity.Name; emp.Id = Guid.NewGuid(); //Assign new ID on save. emp.BusinessLocation = buslocation; //Lookup user profile for authenicated user who is creating business emp.UserProfile = db.UserProfiles.Single(usr => usr.Email == email); emp.Email = emp.UserProfile.Email; emp.FirstName = emp.UserProfile.FirstName; emp.LastName = emp.UserProfile.LastName; emp.MobilePhone = emp.UserProfile.MobilePhone; emp.Type = EmployeeType.FullTime; //Default to Full time employee type emp.IsAdmin = true; emp.ManagerBusinessLocations.Add(buslocation); db.Employees.Add(emp); db.BusinessLocations.Add(buslocation); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, buslocation.Id)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized)); } }