Example #1
0
        public static Trattamento GetTrattamento(int id)
        {
            var sb = new StringBuilder();

            sb.Append("SELECT ");
            sb.Append("*");
            sb.Append(" FROM ");
            sb.Append("trattamento");
            sb.Append(" WHERE ");
            sb.Append("ID=" + id);

            Trattamento trattamento = null;

            SqlLiteHelper.FillEntity(sb.ToString(), reader =>
            {
                trattamento             = new Trattamento();
                trattamento.ID          = id;
                trattamento.Data        = (DateTime)reader["data"];
                trattamento.Descrizione = reader["descrizione"].ToString();
                trattamento.IdPaziente  = (int)(long)reader["ID_paziente"];
                trattamento.IdConsulto  = (int)(long)reader["ID_consulto"];
            });

            return(trattamento);
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Trattamento trattamento = db.Trattamenti.Find(id);

            db.Trattamenti.Remove(trattamento);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "Id,Nome,DurataInMinuti,Prezzo,Descrizione")] Trattamento trattamento)
 {
     if (ModelState.IsValid)
     {
         db.Entry(trattamento).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(trattamento));
 }
Example #4
0
        public static bool SalvaDati(ref Trattamento trattamento, ref string sMsg)
        {
            bool bResult;

            try
            {
                var sb = new StringBuilder();

                var arParams = new List <MySqlLiteParameter>
                {
                    new MySqlLiteParameter("@data", DbType.DateTime, trattamento.Data),
                    new MySqlLiteParameter("@descrizione", DbType.String, trattamento.Descrizione),
                    new MySqlLiteParameter("@id_paziente", DbType.Int32, trattamento.IdPaziente),
                    new MySqlLiteParameter("@id_consulto", DbType.Int32, trattamento.IdConsulto)
                };

                if (trattamento.ID == -1)
                {
                    sb.Append("INSERT INTO ");
                    sb.Append("trattamento");
                    sb.Append("( data, descrizione,id_paziente, id_consulto )");
                    sb.Append(" VALUES ");
                    sb.Append("( @data, @descrizione, @id_paziente, @id_consulto )");

                    int newID;
                    SqlLiteHelper.Insert(sb.ToString(), arParams, out newID);
                    trattamento.ID = newID;
                }
                else
                {
                    arParams.Add(new MySqlLiteParameter("@ID", DbType.Int32, trattamento.ID));

                    sb.Append("UPDATE ");
                    sb.Append("trattamento");
                    sb.Append(" SET ");
                    sb.Append("data=@data,");
                    sb.Append("descrizione=@descrizione,");
                    sb.Append("id_paziente=@id_paziente,");
                    sb.Append("id_consulto=@id_consulto");
                    sb.Append(" WHERE ");
                    sb.Append("ID = @ID");

                    SqlLiteHelper.Update(sb.ToString(), arParams);
                }

                bResult = true;
            }
            catch (Exception ex)
            {
                bResult = false;
                sMsg    = ex.Message;
            }

            return(bResult);
        }
Example #5
0
        public ActionResult Create([Bind(Include = "Id,Nome,DurataInMinuti,Prezzo,Descrizione")] Trattamento trattamento)
        {
            if (ModelState.IsValid)
            {
                db.Trattamenti.Add(trattamento);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trattamento));
        }
Example #6
0
        // GET: Trattamento/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trattamento trattamento = db.Trattamenti.Find(id);

            if (trattamento == null)
            {
                return(HttpNotFound());
            }
            return(View(trattamento));
        }
Example #7
0
        public async Task <IActionResult> Create(Trattamento model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "Consulti", new { id = model.ConsultoId }));
                }
            }
            catch (DbUpdateException ex)
            {
                _logger.LogError(ex, "Trattamento creation failed");
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(model));
        }
Example #8
0
        public async Task <IActionResult> Create(int?consultoId)
        {
            if (consultoId == null)
            {
                return(NotFound());
            }

            var entity = await _context.Consulti
                         .SingleOrDefaultAsync(m => m.ID == consultoId);

            if (entity == null)
            {
                return(NotFound());
            }

            var model = new Trattamento {
                PazienteId = entity.PazienteId, ConsultoId = consultoId.Value
            };

            return(View(model));
        }
Example #9
0
 public IActionResult Put([FromBody] Trattamento contract) => Store(contract, EntityState.Modified);
Example #10
0
 public IActionResult Post([FromBody] Trattamento contract) => Store(contract, EntityState.Added);