Example #1
0
        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());
        }
Example #2
0
        private TimesheetWeekDTO GetTimesheetData(Guid timeSheetId)
        {
            TimesheetWeekDTO val = null;

            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                Task <String> response = httpClient.GetStringAsync("api/TimesheetAPI/" + timeSheetId.ToString());
                val = Task.Factory.StartNew(() => JsonConvert.DeserializeObject <TimesheetWeekDTO>(response.Result)).Result;

                using (var bc = new BusinessController())
                {
                    var businessDTO = bc.GetBusiness(val.BusinessId, this.Session);
                    ViewBag.BusinessId                 = val.BusinessId;
                    ViewBag.HasInternalLocations       = businessDTO.HasMultiInternalLocations;
                    ViewBag.SelectedBusinessName       = businessDTO.Name;
                    ViewBag.SelectedBusinessLocationId = val.BusinessLocationId;

                    if (businessDTO.HasMultiInternalLocations)
                    {
                        ViewBag.BusinessLocations = new SelectList(businessDTO.BusinessLocations, "Id", "Name", ViewBag.SelectedBusinessLocationId);
                    }
                }

                //using (var ec = new EmployerController())
                //{
                //    var employers = ec.GetEmployerSummary(this.Session);
                //    ViewBag.Businesses = new SelectList(employers.Employers, "BusinessId", "BusinessName", ViewBag.BusinessId);
                //}
            }
            return(val);
        }
Example #3
0
        //
        // GET: /Employee/
        public ActionResult Index(Guid businesslocationid)
        {
            BusinessController bc = new BusinessController();
            var busLoc            = bc.GetBusinessLocation(businesslocationid, this.Session);

            ViewBag.BusinessLocationId = businesslocationid;
            ViewBag.BusinessId         = busLoc.BusinessId;
            return(PartialView(GetEmployeesList(businesslocationid)));
        }
Example #4
0
 // 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());
 }
Example #5
0
        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));
        }
Example #6
0
        // GET: /ShiftBlock/
        public ActionResult Index(Guid businesslocationid)
        {
            ViewBag.BusinessLocationId = businesslocationid;
            using (var bc = new BusinessController())
            {
                var bus = bc.GetBusinessLocation(businesslocationid, this.Session);
                ViewBag.BusinessId = bus.BusinessId;
            }

            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                Task <String> response    = httpClient.GetStringAsync("api/ShiftBlockAPI/businesslocation/" + businesslocationid.ToString() + "/shiftblocks");
                var           shiftBlocks = (Task.Factory.StartNew(() => JsonConvert.DeserializeObject <IEnumerable <ShiftBlockDTO> >(response.Result)).Result);
                return(PartialView(shiftBlocks));
            }
        }
Example #7
0
        public ActionResult DeleteConfirmed(Guid businesslocationId, Guid id)
        {
            //Get roles for business
            BusinessController bc = new BusinessController();
            var busLoc            = bc.GetBusinessLocation(businesslocationId, this.Session);


            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                var responseMessage = httpClient.DeleteAsync("api/ShiftBlockAPI/" + id.ToString()).Result;
                responseMessage.EnsureSuccessStatusCode();

                CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS_LOCATION + busLoc.Id.ToString()); //Remove the stale business item from the cache
                CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + busLoc.BusinessId.ToString());  //Remove the stale business item from the cache
            }
            return(RedirectToAction("Index", new { businesslocationid = businesslocationId }));
        }
Example #8
0
        //
        // 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));
            }
        }
Example #9
0
        //
        // GET: /Business/InternalLocationIndex/5
        public ActionResult RecurringShiftIndex(Guid businesslocationid)
        {
            using (BusinessController bc = new BusinessController())
            {
                var         busLocDTO   = bc.GetBusinessLocation(businesslocationid, this.Session);
                BusinessDTO businessDTO = bc.GetBusiness(busLocDTO.BusinessId, this.Session);
                ViewBag.HasInternalLocations = businessDTO.HasMultiInternalLocations;
                ViewBag.BusinessLocationId   = businesslocationid;
                ViewBag.BusinessId           = busLocDTO.BusinessId;
            }

            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                Task <String> response       = httpClient.GetStringAsync("api/ShiftTemplateAPI?businesslocationid=" + businesslocationid.ToString());
                var           shiftTemplates = Task.Factory.StartNew(() => JsonConvert.DeserializeObject <IEnumerable <ShiftTemplateDTO> >(response.Result)).Result;

                return(PartialView(shiftTemplates));
            }
        }
Example #10
0
        //
        // 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());
            }
        }
Example #11
0
        //
        // 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
            }));
        }
Example #12
0
        //
        // 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());
        }
Example #13
0
        // 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));
                }
            }
        }