コード例 #1
0
        public Response updateproduct([FromBody] T_Products value)
        {
            var productlist = dalobject.T_Products.ToList();
            var Product     = (from u in productlist
                               where u.ProductId == value.ProductId
                               select u).SingleOrDefault();

            if (Product != null)
            {
                Product.ProductId          = value.ProductId;
                Product.ProductName        = value.ProductName;
                Product.ProductDescription = value.ProductDescription;
                Product.ProductPrice       = value.ProductPrice;
                Product.CategoryId         = value.CategoryId;
                dalobject.SaveChanges();
                Response rc = new Response();
                response.Status = "Success";
                response.Error  = null;
                response.Data   = Product;
                return(response);
            }
            else
            {
                response.Status = "Fail";
                response.Error  = null;
                response.Data   = null;
                return(response);
            }
        }
コード例 #2
0
        // DELETE: api/Admin/5
        public Response Delete(int id)
        {
            T_Products p = dalobject.T_Products.Find(id);

            dalobject.T_Products.Remove(p);
            try
            {
                dalobject.SaveChanges();
                response.Error  = null;
                response.Status = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Error  = ex;
                response.Status = "Fail";
                return(response);
            }
        }
コード例 #3
0
 // GET: api/Admin
 public Response Post(T_Products data)
 {
     dalobject.T_Products.Add(data);
     //dalobject.SaveChanges();
     try
     {
         dalobject.SaveChanges();
         response.Data   = data;
         response.Error  = null;
         response.Status = "Success";
         return(response);
     }
     catch (Exception ex)
     {
         response.Data   = null;
         response.Error  = ex;
         response.Status = "Fail";
         return(response);
     }
 }
コード例 #4
0
        // GET: api/Admin/5
        public Response Get(int id)
        {
            List <T_Products> user        = dalobject.T_Products.ToList();
            T_Products        productlist = (from u in user
                                             where u.ProductId == id
                                             select u).SingleOrDefault();

            if (productlist != null)
            {
                response.Data   = productlist;
                response.Error  = null;
                response.Status = "Success";
                return(response);
            }
            else
            {
                response.Error  = null;
                response.Status = "Fail";
                return(response);
            }
        }
コード例 #5
0
        public ProductsDTO Add(ProductsDTO products)
        {
            T_Products FruitResult = _dal.Insert <T_Products>(Mapper.Map <T_Products>(products));

            return(Mapper.Map <ProductsDTO>(FruitResult));
        }