コード例 #1
0
        public IHttpActionResult Posttbl_orderDetail(tbl_orderDetail tbl_orderDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            tbl_orderDetail.tbl_order = null;
            db.tbl_orderDetail.Add(tbl_orderDetail);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (tbl_orderDetailExists(tbl_orderDetail.order_id, tbl_orderDetail.name))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tbl_orderDetail.order_id }, tbl_orderDetail));
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            tbl_orderDetail tbl_orderDetail = db.tbl_orderDetail.Find(id);

            db.tbl_orderDetail.Remove(tbl_orderDetail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "order_id,name,amout,price")] tbl_orderDetail tbl_orderDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbl_orderDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.order_id = new SelectList(db.tbl_order, "id", "create_date", tbl_orderDetail.order_id);
     return(View(tbl_orderDetail));
 }
コード例 #4
0
        // GET: OrderDetail/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_orderDetail tbl_orderDetail = db.tbl_orderDetail.Find(id);

            if (tbl_orderDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_orderDetail));
        }
コード例 #5
0
        // GET: OrderDetail/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_orderDetail tbl_orderDetail = db.tbl_orderDetail.Find(id);

            if (tbl_orderDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.order_id = new SelectList(db.tbl_order, "id", "create_date", tbl_orderDetail.order_id);
            return(View(tbl_orderDetail));
        }
コード例 #6
0
        public IHttpActionResult Deletetbl_orderDetail(Guid id, string name)
        {
            tbl_orderDetail tbl_orderDetail = db.tbl_orderDetail.FirstOrDefault(e => e.order_id == id && e.name.Equals(name));

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

            tbl_orderDetail.tbl_order = null;
            db.tbl_orderDetail.Remove(tbl_orderDetail);
            db.SaveChanges();

            return(Ok(tbl_orderDetail));
        }
コード例 #7
0
        public IHttpActionResult Puttbl_orderDetail(Guid id, string name, tbl_orderDetail tbl_orderDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbl_orderDetail.order_id)
            {
                return(BadRequest());
            }

            tbl_orderDetail temp = db.tbl_orderDetail.FirstOrDefault(e => e.order_id == id && e.name.Equals(name));

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

            temp.name      = tbl_orderDetail.name;
            temp.price     = tbl_orderDetail.price;
            temp.amout     = tbl_orderDetail.amout;
            temp.tbl_order = null;

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tbl_orderDetailExists(id, tbl_orderDetail.name))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #8
0
        public IHttpActionResult Puttbl_order(Guid id, tbl_order tbl_order)
        {
            tbl_order cache = tbl_order;

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

            if (id != tbl_order.id)
            {
                return(BadRequest());
            }
            tbl_order.tbl_table = null;
            ICollection <tbl_orderDetail> newDetails = tbl_order.tbl_orderDetail;

            tbl_order.tbl_orderDetail = null;

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tbl_orderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            if (newDetails != null)
            {
                ICollection <tbl_orderDetail> oldDetails = db.tbl_orderDetail.Where(e => e.order_id == id).ToList();


                foreach (var oldDetail in oldDetails)
                {
                    if (!(newDetails.Count(e => e.order_id == oldDetail.order_id && e.name.Equals(oldDetail.name)) > 0))
                    {
                        if (oldDetail != null)
                        {
                            oldDetail.tbl_order = null;
                            db.tbl_orderDetail.Remove(oldDetail);
                            db.SaveChanges();
                        }
                    }
                }

                foreach (var item in newDetails)
                {
                    tbl_orderDetail temp = db.tbl_orderDetail.FirstOrDefault(e => e.order_id == item.order_id && e.name.Equals(item.name));

                    if (temp == null)
                    {
                        item.tbl_order = null;
                        db.tbl_orderDetail.Add(item);
                    }
                    else
                    {
                        temp.name            = item.name;
                        temp.price           = item.price;
                        temp.amout           = item.amout;
                        temp.tbl_order       = null;
                        db.Entry(temp).State = EntityState.Modified;
                    }

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!(db.tbl_orderDetail.Count(e => e.order_id == item.order_id && e.name.Equals(item.name)) > 0))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }

            return(StatusCode(HttpStatusCode.OK));
        }