public IActionResult Update(int id, [FromBody] RightsViewModel right) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Rights _rightDb = _rightsRepository.GetSingle(id); if (_rightDb == null) { return(NotFound()); } else { _rightDb.Name = right.Name; _rightDb.Symbol = right.Symbol; } _rightsRepository.Commit(); right = Mapper.Map <Rights, RightsViewModel>(_rightDb); return(new NoContentResult()); }
public IActionResult Get(int id) { Rights _right = _rightsRepository.GetSingle(a => a.Id == id); if (_right != null) { RightsViewModel _rightsViewModel = Mapper.Map <Rights, RightsViewModel>(_right); return(new OkObjectResult(_rightsViewModel)); } else { return(NotFound()); } }
public IActionResult Create([FromBody] RightsViewModel right) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Rights _newRight = Mapper.Map <RightsViewModel, Rights>(right); _rightsRepository.Add(_newRight); _rightsRepository.Commit(); right = Mapper.Map <Rights, RightsViewModel>(_newRight); return(new OkObjectResult(right)); }
public IActionResult Rights() { string url = "http://www.molsa.gov.il/Open/Rights/Documents/Rights.xml"; byte[] data; using (WebClient webClient = new WebClient()) data = webClient.DownloadData(url); string str = Encoding.GetEncoding("utf-8").GetString(data); XElement doc = XElement.Parse(str); IEnumerable <XElement> childList = from el in doc.Elements() select el; XNamespace ns = "http://Molsa.Moss.MisradHarevacha.Rights"; List <RightsViewModel> rightsViewModels = new List <RightsViewModel>(); int indexer = 0; foreach (XElement e in childList) { indexer++; RightsViewModel rightsViewModel = new RightsViewModel() { Id = indexer, Right = e.Element(ns + "Right").Value, Subject = e.Element(ns + "Subject").Value, Documents = e.Element(ns + "Documents").Value, ResponsibleEntity = e.Element(ns + "ResponsibleEntity").Value, Populations = e.Element(ns + "Populations").Value, RightsEligibilityDetails = e.Element(ns + "RightsEligibilityDetails").Value, RightsType = e.Element(ns + "RightsType").Value }; rightsViewModels.Add(rightsViewModel); } return(View(rightsViewModels)); }