public async Task <ActionResult> Update(int id, [FromBody] IspitUpsertModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (UserResolver.GetUposlenikId(HttpContext.User) != _kursInstancaService.GetInstancaSimple(model.KursInstancaId).UposlenikId)
             {
                 return(Unauthorized("Ova instanca ne pripada predavaču."));
             }
             return(Ok(await _ispitService.Update(id, model)));
         }
         else
         {
             return(BadRequest(model));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(new ApiException(ex.Message, System.Net.HttpStatusCode.BadRequest)));
     }
 }
Exemplo n.º 2
0
 private async void btnPotvrdi_Click(object sender, EventArgs e)
 {
     if (ValidateChildren())
     {
         try
         {
             DateTime myDate = dateVrijeme.Value.Date +
                               vrijemePicker.Value.TimeOfDay;
             IspitModel result  = null;
             var        request = new IspitUpsertModel
             {
                 DatumVrijemeIspita = myDate,
                 KursInstancaId     = instancaId,
                 Lokacija           = txtLokacija.Text
             };
             if (ispitId != null)
             {
                 result = await _ispitService.Update <IspitModel>(ispitId, request);
             }
             else
             {
                 result = await _ispitService.Insert <IspitModel>(request);
             }
             if (result != null)
             {
                 MessageBox.Show("Operacija uspješna.");
                 this.DialogResult = DialogResult.OK;
                 this.Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }