Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        public IHttpActionResult GetRedeSocial(int id)
        {
            RedeSocial redeSocial = db.RedeSocials.Find(id);

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

            return(Ok(redeSocial));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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"));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public long CreateRedeSocial(RedeSocial obj)
        {
            long retorno = 0;

            try
            {
                this._dependency.RedeSociais.Add(obj);
                retorno = obj.IdRedeSocial;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retorno);
        }
Exemplo n.º 10
0
 public long CreateRedeSocial(RedeSocial obj)
 {
     return(dependency.CreateRedeSocial(obj));
 }
Exemplo n.º 11
0
 public async Task <RedeSocial> AddRedeSocial(RedeSocial model)
 {
     _eventoDbContext.RedeSociais.Add(model);
     _eventoDbContext.SaveChanges();
     return(await _eventoDbContext.RedeSociais.FirstOrDefaultAsync(r => r.Id == model.Id));
 }