示例#1
0
        public IHttpActionResult Delete(int prodid)
        {
            using (DatabasemodelEntities dc = new DatabasemodelEntities())
            {
                bool status = false;

                var v = dc.Products.Where(a => a.prodid == prodid).FirstOrDefault();
                if (v != null)
                {
                    dc.Products.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }

            return(Ok("Ok"));
        }
示例#2
0
        //[HttpPost]  add  and update records
        public IHttpActionResult Save(Product Prod)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (DatabasemodelEntities dc = new DatabasemodelEntities())
                {
                    if (Prod.prodid > 0)
                    {
                        var v = dc.Products.Where(a => a.productname == Prod.productname).FirstOrDefault();
                        if (v != null)
                        {
                            v.productname = Prod.productname;
                            v.proditeam   = Prod.proditeam;
                            v.Prodprice   = Prod.Prodprice;
                        }

                        else
                        {
                            dc.Products.Add(Prod);


                            dc.SaveChanges();
                            status = true;
                        }
                    }
                    else
                    {
                        var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();//

                        return(Ok("error"));
                    }
                }
            }
            return(Ok("ok"));
        }