public async Task <EmployeeShiftDto> DeleteEmployeeShift()
        {
            int    id = 1165;//idEmployee
            string responseBodyEmployeeShift = await this._clientService.DeleteResponse(localhostApi + "api/EmployeeShiftApi/" + id, "", validJwt);

            EmployeeShiftDto employeeDto = JsonConvert.DeserializeObject <EmployeeShiftDto>(responseBodyEmployeeShift);

            return(employeeDto);
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            string responseBodyEmployeeShift = await this._clientService.DeleteResponse(this._configuration["AppSettings:ApiRest"] + "api/EmployeeShiftApi/" + id);

            EmployeeShiftDto employeeShift = JsonConvert.DeserializeObject <EmployeeShiftDto>(responseBodyEmployeeShift);

            return(RedirectToAction(nameof(Index), new
            {
                idEmployee = employeeShift.IdEmployee
            }));
        }
        public IActionResult RemoveEmployeeShift(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "EmployeeShiftFunctionApi/{id:int}")] HttpRequestMessage req, int id, ExecutionContext context)
        {
            /*Validate JWT*/
            if ((SecurityJwt.ValidateTokenWithRoleAsync(req.Headers.Authorization, context.FunctionAppDirectory, "Admin")) == null)
            {
                return(new UnauthorizedResult());
            }
            /*Code*/
            var result = db.DeleteEmployeeShift(id);
            EmployeeShiftDto responseMessage = _mapper.Map <EmployeesShifts, EmployeeShiftDto>(result);

            return(new OkObjectResult(responseMessage));
        }
        public async Task <EmployeeShiftDto> CreateEmployeeShift()
        {
            EmployeeShiftDto employeeShift = new EmployeeShiftDto();

            employeeShift.IdEmployee = 23;
            employeeShift.InitHour   = 1;
            employeeShift.EndHour    = 2;
            employeeShift.WorkDay    = DateTime.Now;
            string responseBodyEmployeeShift = await this._clientService.PostResponse(localhostApi + "api/EmployeeShiftApi", JsonConvert.SerializeObject(employeeShift), validJwt);

            EmployeeShiftDto employeeDto = JsonConvert.DeserializeObject <EmployeeShiftDto>(responseBodyEmployeeShift);

            return(employeeDto);
        }
Beispiel #5
0
        // GET: EmployeesShifts/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            string responseBodyEmployeeShift = await this._clientService.GetResponse(this._configuration["AppSettings:ApiRest"] + "api/EmployeeShiftApi/" + id);

            EmployeeShiftDto employeeShift = JsonConvert.DeserializeObject <EmployeeShiftDto>(responseBodyEmployeeShift);
            var employeesShifts            = employeeShift;

            if (employeesShifts == null)
            {
                return(NotFound());
            }

            return(View(employeesShifts));
        }
        public async Task <IActionResult> UpdateEmployeeShift(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "EmployeeShiftFunctionApi/{id:int}")] HttpRequestMessage req, int id, ExecutionContext context)
        {
            /*Validate JWT*/
            if ((SecurityJwt.ValidateTokenWithRoleAsync(req.Headers.Authorization, context.FunctionAppDirectory, "Admin")) == null)
            {
                return(new UnauthorizedResult());
            }
            /*Code*/
            var content = await req.Content.ReadAsStringAsync();

            EmployeeShiftDto employeeShiftDto = JsonSerializer.Deserialize <EmployeeShiftDto>(content);
            EmployeesShifts  employeesShiftDb = _mapper.Map <EmployeeShiftDto, EmployeesShifts>(employeeShiftDto);
            var result = db.UpdateEmployeeShift(employeesShiftDb);
            EmployeeShiftDto responseMessage = _mapper.Map <EmployeesShifts, EmployeeShiftDto>(result);

            return(new OkObjectResult(responseMessage));
        }
Beispiel #7
0
        private bool ValidateShift(EmployeeShiftDto shift)
        {
            string responseBodyEmployeeShift      = this._clientService.GetResponse(this._configuration["AppSettings:ApiRest"] + "api/EmployeeShiftApi").GetAwaiter().GetResult();
            List <EmployeeShiftDto> employeeShift = JsonConvert.DeserializeObject <List <EmployeeShiftDto> >(responseBodyEmployeeShift);

            if (employeeShift.FirstOrDefault(elem => elem.IdEmployee == shift.IdEmployee &&
                                             elem.WorkDay == shift.WorkDay &&
                                             ((elem.InitHour < shift.InitHour && elem.EndHour > shift.InitHour) ||
                                              (elem.InitHour < shift.EndHour && elem.EndHour > shift.EndHour) ||
                                              (elem.InitHour == shift.InitHour && elem.EndHour <= shift.EndHour) ||
                                              (elem.InitHour >= shift.InitHour && elem.EndHour <= shift.EndHour) ||
                                              (elem.InitHour > shift.InitHour && elem.EndHour < shift.EndHour))
                                             ) != null)
            {
                TempData["Error"] = "The shift " + shift.InitHour + " - " + shift.EndHour + " is already included on day " + shift.WorkDay;
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        private List <EmployeeShiftDto> GetShiftsForEmployee(EmployeeShiftModel employeeShiftModel)
        {
            List <EmployeeShiftDto> employeesShifts = new List <EmployeeShiftDto>();
            var dates = new List <DateTime>();

            for (var dt = employeeShiftModel.EmployeeShift.WorkDay; dt <= employeeShiftModel.EndDate; dt = dt.AddDays(1))
            {
                dates.Add(dt);
            }

            foreach (DateTime date in dates)
            {
                EmployeeShiftDto employeeShift = new EmployeeShiftDto();
                employeeShift.InitHour   = employeeShiftModel.EmployeeShift.InitHour;
                employeeShift.EndHour    = employeeShiftModel.EmployeeShift.EndHour;
                employeeShift.WorkDay    = date;
                employeeShift.IdEmployee = employeeShiftModel.EmployeeShift.IdEmployee;
                employeesShifts.Add(employeeShift);
            }
            return(employeesShifts);
        }