예제 #1
0
        public ActionResult GetSingleSkipper(ApiVersion version, int id)
        {
            SkipperEntity skipperItem = _skipperRepository.GetSingle(id);

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

            return(Ok(ExpandSingleSkipperItem(skipperItem, version)));
        }
예제 #2
0
        private dynamic ExpandSingleSkipperItem(SkipperEntity skipperItem, ApiVersion version)
        {
            var        links = GetLinks(skipperItem.SkipperId, version);
            SkipperDto item  = _mapper.Map <SkipperDto>(skipperItem);

            var resourceToReturn = item.ToDynamic() as IDictionary <string, object>;

            resourceToReturn.Add("links", links);

            return(resourceToReturn);
        }
예제 #3
0
        public ActionResult <SkipperDto> AddSkipper(ApiVersion version, [FromBody] SkipperCreateDto skipperCreateDto)
        {
            if (skipperCreateDto == null)
            {
                return(BadRequest());
            }

            SkipperEntity toAdd = _mapper.Map <SkipperEntity>(skipperCreateDto);

            _skipperRepository.Add(toAdd);

            if (!_skipperRepository.Save())
            {
                throw new Exception("Creating a skipper failed on save.");
            }

            SkipperEntity newSkipperItem = _skipperRepository.GetSingle(toAdd.SkipperId);

            return(CreatedAtRoute(nameof(GetSingleSkipper), new { version = version.ToString(), id = newSkipperItem.SkipperId },
                                  _mapper.Map <SkipperDto>(newSkipperItem)));
        }
예제 #4
0
 public SkipperEntity Update(int id, SkipperEntity item)
 {
     _dbContext.Skippers.Update(item);
     return(item);
 }
예제 #5
0
        public void Delete(int id)
        {
            SkipperEntity item = GetSingle(id);

            _dbContext.Skippers.Remove(item);
        }
예제 #6
0
 public void Add(SkipperEntity item)
 {
     _dbContext.Skippers.Add(item);
 }