public async Task <ActionResult> UpdateCase(int case_id, string token, string email, [FromBody] UpdateCase @case) { CaseDetailsDTO caseuser = await _userService.GetCaseAsync(case_id); if (caseuser == null) { return(NotFound()); } if (caseuser.User_email != email) { return(NotFound()); } string key = _cache.Get <string>("key"); if ($"{email}-{token}" != key) { return(NotFound()); } await _userService.UpdateCaseAsync(case_id, @case); return(Created("/cases", null)); }
public async Task <ActionResult> SetComment(int id, [FromBody] UpdateCase data) { CaseDetailsDTO @case = await _userService.GetCaseAsync(id); if (@case == null) { return(NotFound()); } await _userService.UpdateCaseAsync(id, data); return(NoContent()); }
public async Task <ActionResult <CaseDetailsDTO> > GetCase(int id) { CaseDetailsDTO @case = await _userService.GetCaseAsync(id); if (@case == null) { NotFound(); } if (@case.User_email != UserEmail) { Forbid(); } return(Json(@case)); }
//Tetiana metode for å returnere saker. Enten alle saker, eller saker for et brukernavn public List <CaseDetailsDTO> GetCaseDetails(string username) { try { var caseList = new List <CaseDetailsDTO>(); if (username == null) { var caseListfromDb = _dbContext.Form.ToList(); foreach (var c in caseListfromDb) { var caseDetails = new CaseDetailsDTO { CaseId = c.Id, UserName = c.Navn, CaseDetails = c.Beskrivelse, DateCreated = c.Date, CategoryId = c.CategoryId, CategoryName = c.Categories.Category_name, }; caseList.Add(caseDetails); } } else { var caseListfromDb = _dbContext.Form.Where(x => x.Navn == username).ToList(); foreach (var c in caseListfromDb) { var caseDetailsForUser = new CaseDetailsDTO { CaseId = c.Id, UserName = c.Navn, CaseDetails = c.Beskrivelse, DateCreated = c.Date, }; caseList.Add(caseDetailsForUser); } } return(caseList); } catch (Exception ex) { throw; } }