Beispiel #1
0
        public IHttpActionResult update([FromBody] AdvertComments advertComments, int id)
        {
            int user_id = Users.GetUserId(User);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!db.advert_comments.Any(ac => ac.advert_id == advertComments.advert_id && ac.id == id && ac.user_id == user_id))
            {
                return(NotFound());
            }

            using (var dbContext = new DatabaseContext())
            {
                advertComments.id                     = id;
                advertComments.user_id                = user_id;
                advertComments.updated_date           = DateTime.Now;
                dbContext.Entry(advertComments).State = System.Data.Entity.EntityState.Modified;
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    ExceptionThrow.Throw(ex);
                }
            }
            return(Ok(advertComments));
        }
Beispiel #2
0
        public IHttpActionResult add([FromBody] AdvertComments advertComments)
        {
            int   user_id = Users.GetUserId(User);
            Users user    = db.users.Find(user_id);


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!db.advert.Any(a => a.id == advertComments.advert_id))
            {
                return(NotFound());
            }

            advertComments.user_id = user_id;
            db.advert_comments.Add(advertComments);

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                ExceptionThrow.Throw(ex);
            }
            return(Ok(advertComments));
        }
Beispiel #3
0
        public IHttpActionResult read(int id)
        {
            int            user_id = Users.GetUserId(User);
            AdvertComments comment = db.advert_comments.Where(ac => ac.id == id).FirstOrDefault();

            if (comment == null)
            {
                return(NotFound());
            }
            return(Ok(comment));
        }
Beispiel #4
0
        public IHttpActionResult delete(int id)
        {
            int            user_id = Users.GetUserId(User);
            AdvertComments comment = db.advert_comments.Where(ac => ac.id == id).FirstOrDefault();

            if (comment == null)
            {
                return(NotFound());
            }
            db.advert_comments.Remove(comment);
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                ExceptionThrow.Throw(ex);
            }
            return(Ok());
        }