Beispiel #1
0
        // PUT api/NguoiDung/5
        public HttpResponseMessage PutNguoiDung(string id, NguoiDung nguoidung)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != nguoidung.MaNguoiDung)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(nguoidung).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #2
0
        // PUT api/MonAn/5
        public HttpResponseMessage PutMonAn(int id, MonAn monan)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != monan.MaMonAn)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(monan).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #3
0
        public String Add(string id)
        {
            string[] splits = id.Split('-');

            string UserId = splits[0];
            int    FoodId = int.Parse(splits[1]);

            var results = db.Thich.Where(o => o.MaNguoiDung == UserId).Where(o => o.MaMonAn == FoodId);

            try
            {
                if (results.Count() != 0)
                {
                    return(results.Count().ToString());
                }

                Thich like = new Thich();
                like.MaMonAn     = FoodId;
                like.MaNguoiDung = UserId;

                db.Thich.Add(like);
                db.SaveChanges();

                return((results.Count()).ToString());
            }
            catch
            {
                return(results.Count().ToString());
            }
        }
Beispiel #4
0
        // POST api/BinhLuan
        public HttpResponseMessage PostBinhLuan(BinhLuan binhluan)
        {
            binhluan.NgayDang = DateTime.Now;
            if (ModelState.IsValid)
            {
                db.BinhLuan.Add(binhluan);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, binhluan);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = binhluan.MaBinhLuan }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }