Esempio n. 1
0
        public IActionResult GetMany([FromHeader] string sender,
                                     int?page,
                                     int?pageSize,
                                     int?warehouseId)
        {
            try
            {
                if (page == null || pageSize == null)
                {
                    return(BadRequest("'page' and 'pageSize' parameters are required"));
                }
                if (page < 1 || pageSize < 1)
                {
                    return(BadRequest("Parameters must be positive"));
                }
                if (sender == null)
                {
                    return(Unauthorized());
                }

                object   pagedResult = null;
                Employee user        = JsonConvert.DeserializeObject <Employee>(sender);

                if (warehouseId != null)
                {
                    if (user.IsAdmin() || user.WarehouseId == warehouseId.Value)
                    {
                        pagedResult = impServ.GetManyInWarehouse(page.Value, pageSize.Value, warehouseId.Value);
                    }
                }
                else
                {
                    if (user.IsAdmin())
                    {
                        pagedResult = impServ.GetMany(page.Value, pageSize.Value);
                    }
                }

                if (pagedResult == null)
                {
                    return(Unauthorized());
                }
                else
                {
                    return(Ok(pagedResult));
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                return(StatusCode(500));
            }
        }