Exemplo n.º 1
0
        public IActionResult Put(int id, [FromBody] TagDefViewModel tagdef)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TagDef _tagdefDb = _tagdefRepository.GetSingle(id);

            if (_tagdefDb == null)
            {
                return(NotFound());
            }
            else
            {
                _tagdefDb.Source              = tagdef.Source;
                _tagdefDb.Name                = tagdef.Name;
                _tagdefDb.Description         = tagdef.Description;
                _tagdefDb.ExtendedDescription = tagdef.ExtendedDescription;
                _tagdefRepository.Commit();
            }

            tagdef = Mapper.Map <TagDef, TagDefViewModel>(_tagdefDb);

            return(new NoContentResult());
        }
Exemplo n.º 2
0
        public IActionResult GetTagDef(int id)
        {
            TagDef _tagdef = _tagdefRepository.GetSingle(u => u.Id == id);

            if (_tagdef != null)
            {
                TagDefViewModel _tagdefVM = Mapper.Map <TagDef, TagDefViewModel>(_tagdef);
                return(new OkObjectResult(_tagdefVM));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 3
0
        public IActionResult Get()
        {
            if (Request.Query.Count() > 0)
            {
                //List<TagDef> result;
                foreach (var param in Request.Query)
                {
                    TagDef _tagdef = _tagdefRepository.GetSingle(u => u.Name.Equals(param.Value, StringComparison.CurrentCultureIgnoreCase));

                    if (_tagdef != null)
                    {
                        TagDefViewModel _tagdefVM = Mapper.Map <TagDef, TagDefViewModel>(_tagdef);
                        return(new OkObjectResult(_tagdefVM));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            var pagination = Request.Headers["Pagination"];

            if (!string.IsNullOrEmpty(pagination))
            {
                string[] vals = pagination.ToString().Split(',');
                int.TryParse(vals[0], out page);
                int.TryParse(vals[1], out pageSize);
            }

            int currentPage     = page;
            int currentPageSize = pageSize;
            var totalRecs       = _tagdefRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalRecs / pageSize);

            IEnumerable <TagDef> _tagdefs = _tagdefRepository
                                            .GetAll()
                                            .OrderBy(u => u.Id)
                                            .Skip((currentPage - 1) * currentPageSize)
                                            .Take(currentPageSize)
                                            .ToList();

            IEnumerable <TagDefViewModel> _tagdefsVM = Mapper.Map <IEnumerable <TagDef>, IEnumerable <TagDefViewModel> >(_tagdefs);

            Response.AddPagination(page, pageSize, totalRecs, totalPages);

            return(new OkObjectResult(_tagdefsVM));
        }
Exemplo n.º 4
0
        public IActionResult GetTagsCurrentValue(string TagName)
        {
            if (string.IsNullOrEmpty(TagName))
            {
                return(NotFound());
            }

            TagDef _tagdef = _tagdefRepository.GetSingle(u => u.Name.Equals(TagName, StringComparison.CurrentCultureIgnoreCase));

            if (_tagdef != null)
            {
                TagDefViewModel _userVM = Mapper.Map <TagDef, TagDefViewModel>(_tagdef);
                return(new OkObjectResult(_userVM));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 5
0
        public IActionResult Create([FromBody] TagDefViewModel tagdef)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TagDef _newTag = new TagDef {
                Name = tagdef.Name, Description = tagdef.Description, ExtendedDescription = tagdef.ExtendedDescription
            };

            _tagdefRepository.Add(_newTag);
            _tagdefRepository.Commit();

            tagdef = Mapper.Map <TagDef, TagDefViewModel>(_newTag);

            CreatedAtRouteResult result = CreatedAtRoute("GetTagDef", new { controller = "TagDefs", id = tagdef.Id }, tagdef);

            return(result);
        }