public IHttpActionResult PutRedeSocial(int id, RedeSocial redeSocial) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != redeSocial.ID_RedeSocial) { return(BadRequest()); } db.Entry(redeSocial).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RedeSocialExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task UpdateRedeSocial(int id, RedeSocial model) { var redeSocial = _eventoDbContext.RedeSociais.SingleOrDefault(r => r.Id == id); if (redeSocial == null) { throw new ArgumentException("Rede Social não encotrada"); } redeSocial.Update(model.Nome, model.URL); await _eventoDbContext.SaveChangesAsync(); }
public IHttpActionResult GetRedeSocial(int id) { RedeSocial redeSocial = db.RedeSocials.Find(id); if (redeSocial == null) { return(NotFound()); } return(Ok(redeSocial)); }
public IHttpActionResult PostRedeSocial(RedeSocial redeSocial) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.RedeSocials.Add(redeSocial); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = redeSocial.ID_RedeSocial }, redeSocial)); }
public IHttpActionResult GetRedeSocialByAutor(int id) { var id_red = from red in db.redeSocials where red.Id_aut == id select red.ID_RedeSocial; RedeSocial redeSocial = db.redeSocials.Find(id_red.First()); if (redeSocial == null) { return(NotFound()); } return(Ok(redeSocial)); }
public void RedeSocialNameUriTest() { var facebook = new RedeSocial("Facebook", "https://www.facebook.com"); Assert.AreEqual(facebook.Nome, "Facebook"); Assert.AreEqual(facebook.Uri, new Uri("https://www.facebook.com")); var twitter = new RedeSocial("Twitter", "https://twitter.com"); Assert.AreEqual(twitter.Nome, "Twitter"); Assert.AreEqual(twitter.Uri, new Uri("https://twitter.com")); }
public IHttpActionResult DeleteRedeSocial(int id) { RedeSocial redeSocial = db.RedeSocials.Find(id); if (redeSocial == null) { return(NotFound()); } db.RedeSocials.Remove(redeSocial); db.SaveChanges(); return(Ok(redeSocial)); }
public RedeSocial GetRedeSociais(long idRedeSocial) { RedeSocial retorno = new RedeSocial(); try { retorno = this._dependency.RedeSociais.FirstOrDefault(x => x.IdRedeSocial == idRedeSocial); } catch (Exception ex) { throw ex; } return(retorno); }
public long CreateRedeSocial(RedeSocial obj) { long retorno = 0; try { this._dependency.RedeSociais.Add(obj); retorno = obj.IdRedeSocial; } catch (Exception ex) { throw ex; } return(retorno); }
public long CreateRedeSocial(RedeSocial obj) { return(dependency.CreateRedeSocial(obj)); }
public async Task <RedeSocial> AddRedeSocial(RedeSocial model) { _eventoDbContext.RedeSociais.Add(model); _eventoDbContext.SaveChanges(); return(await _eventoDbContext.RedeSociais.FirstOrDefaultAsync(r => r.Id == model.Id)); }