public async Task <TreningModel> Update(int id, TreningModel model) { try { var trening = _context.Trening .Where(k => k.Id == id) .FirstOrDefault(); _context.Set <Trening>().Attach(trening); _context.Set <Trening>().Update(trening); //_mapper.Map(model, kurs); ne prolazi zbog id-a pa cu manual trening.Naziv = model.Naziv; trening.SkraceniNaziv = model.SkraceniNaziv; trening.Opis = model.SkraceniNaziv; await _context.SaveChangesAsync(); var returnModel = _mapper.Map <TreningModel>(trening); return(returnModel); } catch (Exception ex) { throw new Exception(ex.Message); } }
private async void btnPotvrdi_Click(object sender, EventArgs e) { try { if (ValidateChildren()) { var insertModel = new TreningModel { Naziv = txtNaziv.Text, Opis = txtOpis.Text, SkraceniNaziv = txtSkraceniNaziv.Text, }; TreningModel result = null; if (id != null) { result = await _treningService.Update <TreningModel>(id, insertModel); } else { result = await _treningService.Insert <TreningModel>(insertModel); id = result.Id; } if (result != null) { MessageBox.Show("Operacija uspješna."); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// // GET: /Trening/ public ActionResult ListaTreninga(bool Abdominals = false, bool Back = false, bool Biceps = false, bool Chest = false, bool Legs = false, bool Shoulders = false, bool Triceps = false, bool SelectAll = false) { TreningModel model = new TreningModel(); model.Abdominals = Abdominals; model.Back = Back; model.Biceps = Biceps; model.Chest = Chest; model.Legs = Legs; model.Shoulders = Shoulders; model.Triceps = Triceps; model.SelectAll = SelectAll; return(View("~/Views/Trening/ListaTreninga.cshtml", model)); }
public async Task <TreningModel> Add(TreningModel model) { try { var noviTrening = _mapper.Map <Trening>(model); _context.Trening.Add(noviTrening); await _context.SaveChangesAsync(); var returnModel = _mapper.Map <TreningModel>(noviTrening); return(returnModel); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> UpdateOsoblje(int id, [FromBody] TreningModel model) { try { if (ModelState.IsValid) { var item = await _treningService.Update(id, model); return(Ok(item)); } else { return(BadRequest(model)); } } catch (Exception) { throw new Exception("Greska trening controller update"); } }
public async Task <ActionResult> Add([FromBody] TreningModel model) { try { if (ModelState.IsValid) { var item = await _treningService.Add(model); return(Ok(item)); } else { return(BadRequest(model)); } } catch (Exception ex) { throw new Exception("Greska trening controller add"); } }
// // GET: /myFitnessTraining/ public ActionResult myFitnessTraining() { TreningModel model = new TreningModel(); return(View(model)); }