public async Task <IActionResult> UposlenikDetalji(int id = 0) { var ulogeResponse = await _restoranApi.GetUlogaAsync(); var gradResponse = await _restoranApi.GetGradAsync(); var model = new UposlenikDetalji(); var response = await _restoranApi.GetKorisnikByIdAsync(id); if (response.IsSuccessStatusCode) { model = _mapper.Map <UposlenikDetalji>(response.Content); model.TrenutneUloge = response.Content.Uloge.Select(i => i.Id).ToList(); foreach (var item in ulogeResponse.Content.Data) { var IsSelected = model.TrenutneUloge.Contains(item.Id); model.SveUloge.Add ( new KorisnikUlogaCheckListItem { Id = item.Id, Name = item.Name, IsSelected = IsSelected } ); } } model.Gradovi = gradResponse.Content.Data.Select ( i => new SelectListItem() { Text = i.Naziv, Value = i.ID.ToString() } ).ToList(); return(View(model)); }
public async Task <IActionResult> UposlenikSnimi(UposlenikDetalji model) { List <string> noveUloge = model.SveUloge.Where(i => i.IsSelected) .Where(i => !model.TrenutneUloge.Contains(i.Id)) .Select(i => i.Name) .ToList(); List <string> obrisaneUloge = model.SveUloge.Where(i => !i.IsSelected) .Where(i => model.TrenutneUloge.Contains(i.Id)) .Select(i => i.Name) .ToList(); var request = new KorisnikUpdateRequest() { NoveUloge = noveUloge, ObrisaneUloge = obrisaneUloge }; await _restoranApi.UpdateKorisnikAsync(model.Id, request); return(Redirect(nameof(Index))); }