コード例 #1
0
        public IHttpActionResult PostCard(Card card)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Please Check Your Data"));
            }

            _context.Cards.Add(card);
            _context.SaveChanges();

            return(Created(new Uri(Request.RequestUri + "/" + card.UserID), card));
        }
コード例 #2
0
        public IHttpActionResult CreateProduct(Product product)
        {
            if ((!ModelState.IsValid) || product.Name == "" || product.NumInStock == 0 || product.Price == 0)
            {
                return(BadRequest("Please check your data"));
            }

            _context.Products.Add(product);
            _context.SaveChanges();

            return(Created(new Uri(Request.RequestUri + "/" + product.ID), product));
        }
コード例 #3
0
        public IHttpActionResult CreateFactory(Factory factory)
        {
            if ((!ModelState.IsValid) || factory.Name == "" || factory.Description == "")
            {
                return(BadRequest("Please check your data"));
            }

            _context.Factories.Add(factory);
            _context.SaveChanges();

            return(Created(new Uri(Request.RequestUri + "/" + factory.ID), factory));
        }
コード例 #4
0
        public IHttpActionResult CreateUser(User user)
        {
            if ((!ModelState.IsValid) || user.UserName == "" || user.Password == "" || user.Type == "")
            {
                return(BadRequest("Please check Your Data"));
            }

            _context.Users.Add(user);
            _context.SaveChanges();

            return(Created(new Uri(Request.RequestUri + "/" + user.ID), user));
        }
コード例 #5
0
        public IHttpActionResult Buy(Buying buying)
        {
            if ((!ModelState.IsValid) || buying.Name == "" || buying.Phone == "" || buying.Address == "" || buying.TotalPrice == 0)
            {
                return(BadRequest("Please check your data"));
            }

            if (buying.ProductID == "")
            {
                return(BadRequest("Please select items to buy"));
            }

            _context.Buyings.Add(buying);
            _context.SaveChanges();
            return(Created(new Uri(Request.RequestUri + "/" + buying.ID), buying));
        }