public ContentController() { this._contentRepository = new ContentRepository(); this._contentTypeRepository = new ContentTypeRepository(); this._contentMapper = new ContentMapper(); this._contentTypeMapper = new ContentTypeMapper(); ViewData["ContentTypes"] = _contentTypeMapper.ToList(_contentTypeRepository.GetList()); }
public IHttpActionResult ContentWithTypes(string type, string search, string sort, int pageNumber) { try { ContentRepository contentRepo = new ContentRepository(); ContentTypeRepository typeRepo = new ContentTypeRepository(); ContentWithTypesCollectionViewModel model = new ContentWithTypesCollectionViewModel(); List<ContentViewModel> lstContents = contentRepo.GetList(type, search, sort, pageNumber); string[] contact_us = { Constants.CONTACT_US }; List<ContentTypeViewModel> lstTypes = typeRepo.GetList(contact_us); model.types = lstTypes; model.contents = lstContents; return Ok(model); } catch (Exception ex) { return BadRequest(ex.Message); } }
public IHttpActionResult SingleContentWithTypes(long id) { try { ContentRepository contentRepo = new ContentRepository(); ContentTypeRepository typeRepo = new ContentTypeRepository(); SingleContentWithTypesCollectionViewModel model = new SingleContentWithTypesCollectionViewModel(); ContentViewModel content = contentRepo.GetSingle(id); if (content.id == 0) { throw new Exception(Error.CONTENT_NOT_FOUND); } string[] contact_us = { Constants.CONTACT_US }; List<ContentTypeViewModel> lstTypes = typeRepo.GetList(contact_us); model.types = lstTypes; model.content = content; return Ok(model); } catch (Exception ex) { return BadRequest(ex.Message); } }