public ActionResult <Shift> Get(int id)
 {
     try
     {
         return(Ok(_shiftService.GetShift(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Received update shift request.");

            var claims = await _authenticationHelper.DecodeToken(req.Headers["Authorization"]);

            if (claims == null || !claims.Identity.IsAuthenticated)
            {
                log.LogInformation("Unauthorised request received.");
                return(new UnauthorizedResult());
            }

            UpdatedShift updatedShift;

            try
            {
                updatedShift = JsonConvert.DeserializeObject <UpdatedShift>(await req.ReadAsStringAsync());
            }
            catch (JsonException)
            {
                return(new BadRequestResult());
            }

            var val = new UpdatedShiftValidator();
            var res = await val.ValidateAsync(updatedShift);

            if (!res.IsValid)
            {
                log.LogInformation("Invalid request received.");
                return(new BadRequestResult());
            }

            var previousShift = await _shiftService.GetShift(claims.Identity.Name, updatedShift.Id);

            if (previousShift == null)
            {
                return(new NotFoundResult());
            }

            previousShift.CrewMate = updatedShift.CrewMate;
            previousShift.Date     = updatedShift.Date;
            previousShift.Duration = updatedShift.Duration;
            previousShift.Event    = updatedShift.Event;
            previousShift.Location = updatedShift.Location;
            previousShift.Role     = updatedShift.Role;

            await _shiftService.UpdateShift(claims.Identity.Name, previousShift);

            return(new OkResult());
        }
Exemple #3
0
        public virtual IActionResult Create(ShiftModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShifts))
            {
                return(AccessDeniedView());
            }

            if (!string.IsNullOrWhiteSpace(model.Code) && _shiftService.GetShift(w => w.Code == model.Code) != null)
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Hero.Admin.Shifts.CodeIsRegister"));
            }


            if (ModelState.IsValid)
            {
                var shift = model.ToEntity <Shift>();
                shift.CreatedOnUtc = DateTime.UtcNow;
                shift.CreatedBy    = _workContext.CurrentCustomer.Id;
                shift.UpdatedBy    = null;
                shift.UpdatedOnUtc = null;
                _shiftService.InsertShift(shift);

                //activity log
                _customerActivityService.InsertActivity("AddNewShift",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewShift"), shift.Id), shift);

                SuccessNotification(_localizationService.GetResource("Hero.Admin.Shifts.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = shift.Id }));
            }

            //prepare model
            model = _shiftModelFactory.PrepareShiftModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Received recent shift request.");

            var claims = await _authenticationHelper.DecodeToken(req.Headers["Authorization"]);

            if (claims == null || !claims.Identity.IsAuthenticated)
            {
                log.LogInformation("Unauthorised request received.");
                return(new UnauthorizedResult());
            }

            var query = req.Query;

            if (!query.Keys.OfType <string>().Contains("id"))
            {
                return(new BadRequestResult());
            }

            var id = query["id"];

            var shift = await _shiftService.GetShift(claims.Identity.Name, id);

            if (shift == null)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(new UpdatedShift
            {
                CrewMate = shift.CrewMate,
                Date = shift.Date,
                Duration = shift.Duration,
                Event = shift.Event,
                Id = shift.Id,
                Location = shift.Location,
                Role = shift.Role
            }));
        }
Exemple #5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Received shift job request.");

            var claims = await _authenticationHelper.DecodeToken(req.Headers["Authorization"]);

            if (claims == null || !claims.Identity.IsAuthenticated)
            {
                log.LogInformation("Unauthorised request received.");
                return(new UnauthorizedResult());
            }

            var query = req.Query;

            if (!query.Keys.OfType <string>().Contains("shiftId"))
            {
                return(new BadRequestResult());
            }

            var shiftId = query["shiftId"];

            var shift = await _shiftService.GetShift(claims.Identity.Name, shiftId);

            if (shift == null)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(shift.Jobs.Select(j => new JobSummary
            {
                Age = j.Age,
                Category = j.Category,
                Gender = j.Gender,
                ReflectionFlag = j.ReflectionFlag
            })));
        }