Example #1
0
        public Model.ApotekaRacun Insert(ApotekaRacunInsertRequest request)
        {
            var entity = _mapper.Map <Database.ApotekaRacun>(request);

            _context.ApotekaRacun.Add(entity);
            _context.SaveChanges();

            return(_mapper.Map <Model.ApotekaRacun>(entity));
        }
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateChildren())
            {
                Model.Requests.ApotekaRacunInsertRequest request = new ApotekaRacunInsertRequest
                {
                    DatumIzdavanja = dtpDatumIzdavanja.Value.Date,
                    PacijentId     = ((Model.Korisnici)cmbPacijent.SelectedItem).Id,
                    ApotekarId     = ((Model.Korisnici)cmbApotekar.SelectedItem).Id
                };

                Model.ApotekaRacun entity = null;
                if (!_id.HasValue)
                {
                    try
                    {
                        entity = await _service.Insert <Model.ApotekaRacun>(request);

                        foreach (DataGridViewRow row in dgvStavke.Rows)
                        {
                            Model.Requests.RacunStavkaInsertRequest request_stavka = new RacunStavkaInsertRequest
                            {
                                ApotekaRacunId = entity.Id,
                                Kolicina       = int.Parse(row.Cells["Kolicina"].Value.ToString()),
                                LijekId        = int.Parse(row.Cells["LijekId"].Value.ToString())
                            };

                            await _serviceRacunStavka.Insert <Model.RacunStavka>(request_stavka);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Greška");
                    }
                }
                else
                {
                    try
                    {
                        entity = await _service.Update <Model.ApotekaRacun>(_id.Value, request);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Greška");
                    }
                }

                if (entity != null)
                {
                    MessageBox.Show("Uspješno izvršeno");
                }
            }
        }
Example #3
0
        public Model.ApotekaRacun Update(int id, ApotekaRacunInsertRequest request)
        {
            var result = _context.ApotekaRacun.Where(x => x.Id == id);

            var entity = result.FirstOrDefault();

            _context.ApotekaRacun.Attach(entity);
            _context.ApotekaRacun.Update(entity);

            _mapper.Map(request, entity);

            _context.SaveChanges();

            return(_mapper.Map <Model.ApotekaRacun>(entity));
        }
Example #4
0
 public Model.ApotekaRacun Update(int id, [FromBody] ApotekaRacunInsertRequest request)
 {
     return(_service.Update(id, request));
 }
Example #5
0
 public Model.ApotekaRacun Insert(ApotekaRacunInsertRequest request)
 {
     return(_service.Insert(request));
 }