Esempio n. 1
0
 public ActionResult Editar(Autore autor)
 {
     this.db.Autores.Attach(autor);
     this.db.Entry(autor).State = System.Data.Entity.EntityState.Modified;
     this.db.SaveChanges();
     return(RedirectToAction("Listar"));
 }
Esempio n. 2
0
        public ActionResult Edit([Bind(Include = "ID,Apellido,Nombre,FechaNacimiento,IdPais")] Autore autore)
        {
            if (ModelState.IsValid)
            {
                db.Entry(autore).State = EntityState.Modified;
                db.SaveChanges();
                #region Otra Opcion para Trabajar con el StoreProcedure es en el Contralador

                /*
                 * if(ModelState.IsValid){
                 *
                 * _context.MyStoreProcedure(parametros del Procedure);
                 *
                 * return RedirecToAction("Index");
                 * }
                 * Sino--
                 * ViewBag.Nacionalida = new SelecList(_context.Paises, "ID", "Descripcion", autore.Nacionalidad)
                 * return View(autore);
                 *
                 */
                #endregion


                return(RedirectToAction("Index"));
            }
            ViewBag.IdPais = new SelectList(db.Paises, "ID", "Nombre", autore.IdPais);
            return(View(autore));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("AutoreId,Nome,Cognome,Email,Telefono,Skills")] Autore autore)
        {
            if (id != autore.AutoreId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(autore);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AutoreExists(autore.AutoreId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(autore));
        }
Esempio n. 4
0
        public ActionResult Editar(int id)
        {
            this.ViewBag.TituloPagina = "Editar Autor";
            Autore autor = this.db.Autores.Find(id);

            return(View(autor));
        }
        public ActionResult Edit(int fazioneId, Autore autoreToEdit)
        {
            var fazioneDto = _fazioneFeRepository.GetFazione(fazioneId);

            if (fazioneDto == null || autoreToEdit == null)
            {
                ModelState.AddModelError("", "Fazione o Autore sono invalidi. Autore non è stato aggiornato!");
            }
            else
            {
                autoreToEdit.Fazione = new Fazione
                {
                    FazioneId   = fazioneDto.FazioneId,
                    NomeFazione = fazioneDto.NomeFazione
                };

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://localhost:44357/api/");
                    var responseTask = client.PutAsJsonAsync($"autori/{autoreToEdit.AutoreId}", autoreToEdit);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        TempData["SuccessMessage"] = "Autore aggiornato con successo";
                        return(RedirectToAction("Index", "Autore"));
                    }

                    ModelState.AddModelError("", "Errore inaspettato. Autore non aggiornato");
                }
            }

            return(View(autoreToEdit));
        }
Esempio n. 6
0
        public ActionResult Agregar()
        {
            ViewBag.Nacionalidad = new SelectList(db.Paises, "ID", "Descripcion");
            Autore autor = new Autore();

            return(View(autor));
        }
Esempio n. 7
0
    protected void bt_submeter_Click(object sender, EventArgs e)
    {
        GridViewRow row = gv_autores.SelectedRow;
        Autore aAntigo = null;
        if (row != null)
        {
            aAntigo = editora.Autores.Find(row.Cells[1].Text);
        }
        Autore aNovo = new Autore();

        aNovo.IDAutor = int.Parse(tx_id.Text);
        aNovo.Nome = tx_nome.Text;
        aNovo.PaisOrigem = tx_pais.Text;
        aNovo.ResumoObra = tx_resumo.Text;
        aNovo.PremioNobel = chk_nobel.Checked;

        if (aAntigo != null)
        {
            editora.Autores.Remove(aAntigo);
        }
        editora.Autores.Add(aNovo);
        editora.SaveChanges();

        updateGridView();
    }
Esempio n. 8
0
    protected void bt_submeter_Click(object sender, EventArgs e)
    {
        GridViewRow row     = gv_autores.SelectedRow;
        Autore      aAntigo = null;

        if (row != null)
        {
            aAntigo = editora.Autores.Find(row.Cells[1].Text);
        }
        Autore aNovo = new Autore();

        aNovo.IDAutor     = int.Parse(tx_id.Text);
        aNovo.Nome        = tx_nome.Text;
        aNovo.PaisOrigem  = tx_pais.Text;
        aNovo.ResumoObra  = tx_resumo.Text;
        aNovo.PremioNobel = chk_nobel.Checked;

        if (aAntigo != null)
        {
            editora.Autores.Remove(aAntigo);
        }
        editora.Autores.Add(aNovo);
        editora.SaveChanges();

        updateGridView();
    }
        // GET: Autore/Edit/5
        public ActionResult Edit(int FazioneId, int autoreId)
        {
            var autoreDto  = _autoreFeRepository.GetAutore(autoreId);
            var fazioneDto = _autoreFeRepository.GetFazioneOfAnAutore(autoreId);

            Autore autore = null;

            if (fazioneDto == null || autoreDto == null)
            {
                ModelState.AddModelError("", "Fazione o Autore sono invalidi. Autore non è stato aggiornato!");
                autore = new Autore();
            }
            else
            {
                autore = new Autore
                {
                    AutoreId     = autoreDto.AutoreId,
                    NomeAutore   = autoreDto.NomeAutore,
                    Pericolosita = autoreDto.Pericolosita,
                    NoteVarie    = autoreDto.NoteVarie,
                    Fazione      = new Fazione
                    {
                        FazioneId   = fazioneDto.FazioneId,
                        NomeFazione = fazioneDto.NomeFazione
                    }
                };
            }

            return(View(autore));
        }
Esempio n. 10
0
        public ActionResult Eliminar(int id)
        {
            Autore autor = this.db.Autores.Find(id);

            this.db.Autores.Remove(autor);
            this.db.SaveChanges();
            return(RedirectToAction("Listar"));
        }
Esempio n. 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            Autore autore = db.Autores.Find(id);

            db.Autores.Remove(autore);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
 public AutoreInserimentoModel(Autore autore, bool selected)
 {
     Id       = autore.Id;
     Nome     = autore.Nome;
     Email    = autore.Email;
     Telefono = autore.Telefono;
     Skill    = autore.Skill;
     Selected = selected;
 }
Esempio n. 13
0
        public void RegistraPresentazione(Autore a, Presentazione p)
        {
            contesto.Registrazioni.Add(new Registrazione
            {
                Autore        = a.Id,
                Presentazione = p.Id
            });

            contesto.SaveChanges();
        }
Esempio n. 14
0
 public ActionResult Agregar(Autore autor)
 {
     if (ModelState.IsValid)
     {
         db.Autores.Add(autor);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(autor));
 }
Esempio n. 15
0
 public VMAutori(Autore a, bool selected)
 {
     AutoreId = a.AutoreId;
     Nome     = a.Nome;
     Cognome  = a.Cognome;
     Email    = a.Email;
     Telefono = a.Telefono;
     Skills   = a.Skills;
     Selected = selected;
 }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("AutoreId,Nome,Cognome,Email,Telefono,Skills")] Autore autore)
        {
            if (ModelState.IsValid)
            {
                _context.Add(autore);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(autore));
        }
Esempio n. 17
0
 public ActionResult Edit([Bind(Include = "ID,Apellido,Nombre,FechaNacimiento,Nacionalidad")] Autore autore)
 {
     if (ModelState.IsValid)
     {
         db.Entry(autore).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Nacionalidad = new SelectList(db.Paises, "ID", "Descripcion", autore.Nacionalidad);
     return(View(autore));
 }
Esempio n. 18
0
        public ActionResult Create([Bind(Include = "ID,Apellido,Nombre,FechaNacimiento,IdPais")] Autore autore)
        {
            if (ModelState.IsValid)
            {
                db.Autores.Add(autore);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdPais = new SelectList(db.Paises, "ID", "Nombre", autore.IdPais);
            return(View(autore));
        }
Esempio n. 19
0
        // GET: Autores/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Autore autore = db.Autores.Find(id);

            if (autore == null)
            {
                return(HttpNotFound());
            }
            return(View(autore));
        }
Esempio n. 20
0
 public ActionResult Edit([Bind(Include = "ID,Apellido,Nombre,FechaNacimiento,Nacionalidad")] Autore autore)
 {
     if (ModelState.IsValid)
     {
         //USAR STORED PROCEDURE
         //db.Entry(autore).State = EntityState.Modified;
         //db.SaveChanges();
         BibliotecaOKEntities db = new BibliotecaOKEntities();
         db.ProcModificaAutor(autore.ID, autore.Apellido, autore.Nombre, autore.FechaNacimiento, autore.Nacionalidad);
         return(RedirectToAction("Index"));
     }
     ViewBag.Nacionalidad = new SelectList(db.Paises, "ID", "Descripcion", autore.Nacionalidad);
     return(View(autore));
 }
Esempio n. 21
0
        // GET: Autores/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Autore autore = db.Autores.Find(id);

            if (autore == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdPais = new SelectList(db.Paises, "ID", "Nombre", autore.IdPais);
            return(View(autore));
        }
Esempio n. 22
0
        public async Task <ResponseBase <Autore> > Create(AutoreDTO data)
        {
            var exist_autor = await Repository.GetAsync(predicate : p => p.Correo == data.Correo);

            if (exist_autor != null)
            {
                return(new ResponseBase <Autore>(message: "Ya existe una Editorial con el nombre o el correo registrado"));
            }

            Autore autor = ConstructModel(data);

            await Repository.AddAsync(autor);

            return(new ResponseBase <Autore>(message: "Solicitud Ok", data: autor, count: 1));
        }
Esempio n. 23
0
        public ActionResult Create(int FazioneId, AutoreViewModel autoremodel)
        {
            using (var client = new HttpClient())
            {
                var fazioneDto = _fazioneFeRepository.GetFazione(FazioneId);

                if (fazioneDto == null || autoremodel == null)
                {
                    ModelState.AddModelError("", "Fazione o Autore sono invalidi. Autore non è stato creato!");
                    return(View(autoremodel));
                }

                var autore = new Autore {
                    NomeAutore   = autoremodel.NomeAutore,
                    NoteVarie    = autoremodel.NoteVarie,
                    Pericolosita = autoremodel.Pericolosita
                };



                autore.Fazione = new Fazione
                {
                    FazioneId   = fazioneDto.FazioneId,
                    NomeFazione = fazioneDto.NomeFazione
                };

                client.BaseAddress = new Uri("https://localhost:44357/api/");
                var responseTask = client.PostAsJsonAsync("autori", autore);
                responseTask.Wait();

                var result = responseTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    var newAutoreTask = result.Content.ReadAsAsync <Autore>();
                    newAutoreTask.Wait();

                    var newAutore = newAutoreTask.Result;
                    TempData["SuccessMessage"] = $"Autore {newAutore.NomeAutore}" +
                                                 $"è stato creato con successo.";
                    return(RedirectToAction("Index", "Autore"));
                }

                ModelState.AddModelError("", "Autore non è stato creato");
            }

            return(View(autoremodel));
        }
Esempio n. 24
0
 public IActionResult AggiungiAutore(Autore autore)
 {
     if (ModelState.IsValid)
     {
         try
         {
             repository.AggiungiAutore(autore);
             return(RedirectToAction("Aggiunto"));
         }
         catch (Exception)
         {
             return(RedirectToAction("Nonaggiunto"));
         }
     }
     return(View(autore));
 }
Esempio n. 25
0
        private void updateSelectedAuthors(int idLibro, string[] selectedAuthors)
        {
            Libro _libro = db.Libros.Include("Autors").Where(x => x.ID == idLibro).First();

            if (selectedAuthors == null)
            {
                _libro.Autors = null;
                return;
            }

            List <int> intSelectedAuthors = new List <int>();

            for (int i = 0; i < selectedAuthors.Length; i++)
            {
                intSelectedAuthors.Add(Int32.Parse(selectedAuthors[i]));
            }

            if (_libro.Autors != null)
            {
                List <Autore> tempList = _libro.Autors.ToList();
                //Delete all the authors that are not contained in the current author list definition
                foreach (Autore _author in tempList)
                {
                    if (!intSelectedAuthors.Contains(_author.ID))
                    {
                        _libro.Autors.Remove(_author);
                    }
                }
            }

            foreach (int i in intSelectedAuthors)
            {
                Autore _autor = db.Autores.Find(i);
                if (_libro.Autors != null)
                {
                    if (!_libro.Autors.Contains(_autor))
                    {
                        _libro.Autors.Add(_autor);
                    }
                }
                else
                {
                    _libro.Autors.Add(_autor);
                }
            }
        }
Esempio n. 26
0
    protected void lbt_eliminar_Click(object sender, EventArgs e)
    {
        GridViewRow row = gv_autores.SelectedRow;

        if (row == null)
        {
            return;
        }

        TableCell cell = row.Cells[1];

        Autore aAntigo = editora.Autores.Find(int.Parse(cell.Text));

        editora.Autores.Remove(aAntigo);
        editora.SaveChanges();

        updateGridView();
    }
Esempio n. 27
0
        public IActionResult UpdateAutore(int autoreId, [FromBody] Autore autoreToUpdate)
        {
            if (autoreToUpdate == null)
            {
                return(BadRequest(ModelState));
            }

            if (autoreId != autoreToUpdate.AutoreId)
            {
                return(BadRequest(ModelState));
            }

            if (!_autoriRepository.AutoreExists(autoreId))
            {
                ModelState.AddModelError("", "L'autore non esiste!");
            }

            if (!_fazioneRepository.FazioneExists(autoreToUpdate.Fazione.FazioneId))
            {
                ModelState.AddModelError("", "La fazione non esiste!");
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(404, ModelState));
            }

            autoreToUpdate.Fazione = _fazioneRepository.GetFazione(autoreToUpdate.Fazione.FazioneId);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_autoriRepository.UpdateAutore(autoreToUpdate))
            {
                ModelState.AddModelError("", $"Qualcosa è andato storto durante l'aggiornamento dell'autore " +
                                         $"{autoreToUpdate.NomeAutore}");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }
Esempio n. 28
0
        public async Task <Autore> CheckAutore(string nome, string cognome)
        {
            var res = await _libreriaContext.Autore.FirstOrDefaultAsync(x => x.Nome.Trim().ToLower() == nome.Trim().ToLower() && x.Cognome.Trim().ToLower() == cognome.Trim().ToLower());

            if (res != null)
            {
                return(res);
            }
            else
            {
                var insert = new Autore();
                insert.Nome    = nome;
                insert.Cognome = cognome;
                _libreriaContext.Autore.Add(insert);
                await _libreriaContext.SaveChangesAsync();

                return(await _libreriaContext.Autore.FirstOrDefaultAsync(x => x.Nome == insert.Nome && x.Cognome == insert.Cognome));
            }
        }
Esempio n. 29
0
        public IActionResult CreateAutore([FromBody] Autore autoreToCreate)
        {
            if (autoreToCreate == null)
            {
                return(BadRequest(ModelState));
            }

            if (!_fazioneRepository.FazioneExists(autoreToCreate.Fazione.FazioneId))
            {
                ModelState.AddModelError("", "Fazione non esiste!");
                return(StatusCode(404, ModelState));
            }

            autoreToCreate.Fazione = _fazioneRepository.GetFazione(autoreToCreate.Fazione.FazioneId);

            var autore = _autoriRepository.GetAutori().Where(a => a.NomeAutore.Trim().ToUpper() == autoreToCreate.NomeAutore.Trim().ToUpper()).FirstOrDefault();

            if (autore != null)
            {
                ModelState.AddModelError("", $"Autore {autoreToCreate.NomeAutore} esiste già");
                return(StatusCode(422, ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_autoriRepository.CreateAutore(autoreToCreate))
            {
                ModelState.AddModelError("", $"Qualcosa è andato storto salvando l'autore " +
                                         $"{autoreToCreate.NomeAutore}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetAutore", new { autoreId = autoreToCreate.AutoreId }, autoreToCreate));
        }
Esempio n. 30
0
 public bool UpdateAutore(Autore autore)
 {
     _autoreContext.Update(autore);
     return(Save());
 }
Esempio n. 31
0
 public bool DeleteAutore(Autore autore)
 {
     _autoreContext.Remove(autore);
     return(Save());
 }