private async void btnSpremi_Click(object sender, EventArgs e)
        {
            if (ValidateChildren())
            {
                try
                {
                    var postModel = new KlijentScoresModel
                    {
                        IspitId = this.model.Id,
                        KlijentPrisustvoScoreList = FillKlijentScoresList()
                    };
                    var result = await _ispitKlijentService.Insert <KlijentScoresModel>(postModel);

                    if (result != null)
                    {
                        MessageBox.Show("Operacija usješna.");
                        await LoadIspit();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        public async Task <KlijentScoresModel> UpdateKlijentScores(int uposlenikId, KlijentScoresModel model)
        {
            try
            {
                var ispit = _context.Ispit
                            .Include(i => i.KlijentiNaIspitu)
                            .Include(i => i.KursInstanca)
                            .Where(i => i.Id == model.IspitId)
                            .FirstOrDefault();
                if (ispit.KursInstanca.UposlenikId != uposlenikId)
                {
                    throw new Exception("Ispit nije organizovao ovaj predavač");
                }
                var returnModel = new KlijentScoresModel
                {
                    IspitId = ispit.Id,
                    KlijentPrisustvoScoreList = new List <KlijentIspitScore>()
                };
                foreach (var entry in model.KlijentPrisustvoScoreList)
                {
                    var entryInDb = ispit.KlijentiNaIspitu.Where(e => e.Id == entry.Id).FirstOrDefault();
                    if (entryInDb != null)
                    {
                        entryInDb.Prisustvovao = entry.Prisustvo;
                        entryInDb.Bodovi       = entry.Bodovi;
                        returnModel.KlijentPrisustvoScoreList
                        .Add(new KlijentIspitScore {
                            Bodovi    = entryInDb.Bodovi,
                            Id        = entryInDb.Id,
                            Prisustvo = entryInDb.Prisustvovao
                        });
                    }
                }
                await _context.SaveChangesAsync();

                return(returnModel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> UpdateKlijentScores([FromBody] KlijentScoresModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _ispitKlijentService.UpdateKlijentScores(UserResolver.GetUposlenikId(HttpContext.User), model);

                    return(Ok(result));
                }
                else
                {
                    return(BadRequest(model));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApiException(ex.Message, System.Net.HttpStatusCode.BadRequest)));
            }
        }