예제 #1
0
        public IActionResult Get(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(BadRequest(nameof(id)));
                }
                id = _protector.Unprotect(id);
                if (int.TryParse(id, out var _id))
                {
                    return(BadRequest(nameof(id)));
                }

                var mapper    = new Mapper <Item, Get>(ItemMapperMethods.MapEntityToGetViewModel, null);
                var data      = _itemRepository.FirstOrDefault(e => e.ID == _id);
                var viewModel = mapper.MapViewModel(data);
                IdProtector <Get> .Protect(_protector, viewModel);

                return(Ok(viewModel));
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }
        }
예제 #2
0
        public IActionResult Get()
        {
            try

            {
                var data = _itemRepository.GetAll();
                if (data == null)
                {
                    return(NotFound("Items not found"));
                }

                var mapper = new Mapper <List <Item>, List <List> >(ItemMapperMethods.MapEntityToListItemViewModel, null);
                var result = new List <List>();

                result = mapper.MapViewModel(data.ToList());
                IdProtector <List> .Protect(_protector, result);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }
        }