public ActionResult Create([Bind(Include = "BusinessId,BusinessLocationId,RoleId,StartTime,FinishTime,FinishNextDay")] ShiftBlockDTO shiftblockdto) { if (shiftblockdto.StartTime > shiftblockdto.FinishTime && !shiftblockdto.FinishNextDay) { ModelState.AddModelError(String.Empty, "Start time must be before the finish time or next day finish must be selected"); } if (ModelState.IsValid) { using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { var responseMessage = httpClient.PostAsJsonAsync("api/ShiftBlockAPI", shiftblockdto).Result; responseMessage.EnsureSuccessStatusCode(); CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS_LOCATION + shiftblockdto.BusinessLocationId.ToString()); //Remove the stale business item from the cache CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + shiftblockdto.BusinessId.ToString()); //Remove the stale business item from the cache return(RedirectToAction("Index", new { businesslocationid = shiftblockdto.BusinessLocationId })); } } //Get roles for business using (BusinessController bc = new BusinessController()) { var busLoc = bc.GetBusinessLocation(shiftblockdto.BusinessLocationId, this.Session); ViewBag.BusinessRoles = bc.GetBusinessRoles(busLoc.BusinessId, this.Session); ViewBag.BusinessId = shiftblockdto.BusinessId; ViewBag.BusinessLocationId = shiftblockdto.BusinessLocationId; } return(PartialView()); }
// GET: /ShiftBlock/Create public ActionResult Create(Guid businesslocationid) { //Get roles for business using (BusinessController bc = new BusinessController()) { var busLoc = bc.GetBusinessLocation(businesslocationid, this.Session); ViewBag.BusinessRoles = bc.GetBusinessRoles(busLoc.BusinessId, this.Session); ViewBag.BusinessLocationId = businesslocationid; } return(PartialView()); }
public ActionResult Create(EmployeeDTO employeedto, List <string> selectedRoles, bool addedAnother = false) { ViewBag.AddedAnother = addedAnother; if (selectedRoles != null) { if (selectedRoles.Count() > 5) { ModelState.AddModelError("", "Maximimum of 5 roles can be added"); } else { employeedto.Roles = new List <RoleDTO>(); foreach (var selectedRole in selectedRoles) { employeedto.Roles.Add(new RoleDTO { Id = Guid.Parse(selectedRole), Name = "PLACEHOLDER" }); } } } if (ModelState.IsValid) { using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { var responseMessage = httpClient.PostAsJsonAsync("/api/EmployeeAPI", employeedto).Result; if (responseMessage.IsSuccessStatusCode) { if (employeedto.AddAnother) { return(RedirectToAction("Create", new { businessLocationId = employeedto.BusinessLocationId, businessId = employeedto.BusinessId, addedAnother = true })); } else { return(RedirectToAction("Index", new { businesslocationid = employeedto.BusinessLocationId })); } } else { //If and error occurred add details to model error. var error = JsonConvert.DeserializeObject <System.Web.Http.HttpError>(responseMessage.Content.ReadAsStringAsync().Result); ModelState.AddModelError(String.Empty, error.Message); } } } //Get roles for business BusinessController bc = new BusinessController(); ViewBag.BusinessRoles = bc.GetBusinessRoles(employeedto.BusinessId, this.Session); return(PartialView(employeedto)); }
// // GET: /Employee/Edit/5 public ActionResult Edit(Guid id) { EmployeeDTO employeeDTO = GetEmployee(id); if (employeeDTO == null) { return(HttpNotFound()); } else { //Get roles for business BusinessController bc = new BusinessController(); ViewBag.BusinessRoles = bc.GetBusinessRoles(employeeDTO.BusinessId, this.Session); //ViewBag.BusinessDetails = GetBusinessSummaryList(); return(PartialView(employeeDTO)); } }
// // GET: /Employee/RoleCreate public ActionResult RoleCreate(Guid employeeid) { EmployeeDTO employeeDTO = GetEmployee(employeeid); if (employeeDTO == null) { return(HttpNotFound()); } else { ViewBag.EmployeeId = employeeid; //Get roles for current employee business which have not already been assigned to employee BusinessController controller = new BusinessController(); List <RoleDTO> roles = controller.GetBusinessRoles(employeeDTO.BusinessId, Session); ViewBag.Roles = (from RoleDTO role in roles where !employeeDTO.Roles.Contains(role) select role).ToList(); ViewBag.BusinessId = employeeDTO.BusinessId; return(PartialView()); } }
// // GET: /Employee/Create public ActionResult Create(Guid?businessLocationId, Guid businessId, bool addedAnother = false) { ViewBag.AddedAnother = addedAnother; //Get roles for business using (BusinessController bc = new BusinessController()) { bc.GetBusinessRoles(businessId, this.Session); BusinessDTO businessDTO = bc.GetBusiness(businessId, this.Session); ViewBag.BusinessRoles = businessDTO.EnabledRoles; ViewBag.SelectedBusinessName = businessDTO.Name; if (!businessLocationId.HasValue) { var enabledBusinessLocations = businessDTO.BusinessLocations.Where(e => e.Enabled); //Ensure the business only has one location then set to this, otherwise throw an exception if (enabledBusinessLocations.Count() == 1) { ViewBag.SelectedBusinessLocationId = enabledBusinessLocations.First().Id; } else { throw new Exception("Business location must be specified."); } } else { ViewBag.SelectedBusinessLocationId = businessLocationId.Value; } ViewBag.BusinessLocations = new SelectList(businessDTO.BusinessLocations, "Id", "Name", ViewBag.SelectedBusinessLocationId); // ViewBag.HasInternalLocations = businessDTO.HasMultiInternalLocations; } return(PartialView(new EmployeeDTO { BusinessId = businessId, BusinessLocationId = (Guid)ViewBag.SelectedBusinessLocationId, IsActive = true })); }
// // GET: /Business/InternalLocationCreate public ActionResult RecurringShiftCreate(Guid businessLocationId, Guid businessId) { ViewBag.BusinessLocationId = businessLocationId; //Get roles for business using (BusinessController bc = new BusinessController()) { bc.GetBusinessRoles(businessId, this.Session); BusinessDTO businessDTO = bc.GetBusiness(businessId, this.Session); ViewBag.BusinessRoles = businessDTO.EnabledRoles; ViewBag.BusinessId = businessId; ViewBag.BusinessLocations = new SelectList(businessDTO.BusinessLocations, "Id", "Name", ViewBag.BusinessLocationId); var busLocDTO = businessDTO.BusinessLocations.FirstOrDefault(b => b.Id == businessLocationId); ViewBag.HasInternalLocations = businessDTO.HasMultiInternalLocations; ViewBag.BusinessInternalLocations = busLocDTO.GetEnabledInternalLocations(); } using (EmployeeController empController = new EmployeeController()) ViewBag.BusinessEmployees = empController.GetEmployeesList(businessLocationId, Session); return(PartialView()); }
// GET: /ShiftBlock/Edit/5 public ActionResult Edit(Guid?id, Guid businesslocationId) { //Get roles for business BusinessController bc = new BusinessController(); var busLoc = bc.GetBusinessLocation(businesslocationId, this.Session); ViewBag.BusinessRoles = bc.GetBusinessRoles(busLoc.BusinessId, this.Session); ViewBag.BusinessId = busLoc.BusinessId; ViewBag.BusinessLocationId = businesslocationId; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { Task <String> response = httpClient.GetStringAsync("api/ShiftBlockAPI/" + id.ToString()); var shiftBlockDTO = (Task.Factory.StartNew(() => JsonConvert.DeserializeObject <ShiftBlockDTO>(response.Result)).Result); return(PartialView(shiftBlockDTO)); } } }