public IActionResult Get()
        {
            try
            {
                IEnumerable <Assignment> results = null;
                ClaimsPrincipal          user    = HttpContext.User;
                if (user.Claims.SingleOrDefault(x => x.Type == ClaimTypes.Role)?.Value == "Admin")
                {
                    results = assignmentManager.GetAll();
                }
                else
                {
                    int repId = Convert.ToInt32(user.Claims.FirstOrDefault(x => x.Type == "RepId")?.Value);
                    if (periodManager == null)
                    {
                        return(BadRequest(config["Error:Default"]));
                    }

                    Period period = periodManager.Find(x => x.IsOpen).SingleOrDefault();
                    if (period != null)
                    {
                        results = assignmentManager.Get(null, repId, period.PeriodId);
                    }
                }

                return(Ok(results));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to get all assignments: {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
Esempio n. 2
0
        public IActionResult Search([FromQuery] Period period)
        {
            try
            {
                IEnumerable <Period> periods = periodManager.Find(x =>
                                                                  x.PeriodId == period.PeriodId &&
                                                                  x.IsOpen == period.IsOpen &&
                                                                  x.StartDate == period.StartDate &&
                                                                  x.EndDate == period.EndDate);

                return(Ok(periods));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to find period(s): {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
Esempio n. 3
0
        public IActionResult Assignments(int id)
        {
            try
            {
                Period openPeriod = periodManager.Find(x => x.IsOpen).SingleOrDefault();
                if (openPeriod == null)
                {
                    return(BadRequest(config["Error:Default"]));
                }

                IEnumerable <Assignment> assignments = assignmentManager.Get(null, id, openPeriod.PeriodId);

                return(Ok(assignments));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to get assignments for rep {id}: {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }