Exemple #1
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            return(View(product));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "ID,FullName,Description,SellersID")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SellersID = new SelectList(db.Sellers, "ID", "FullName", item.SellersID);
            return(View(item));
        }
Exemple #3
0
        public ActionResult Create([Bind(Include = "ID,ItemID,BuyerID,Price,TimeStamp")] Bid bid)
        {
            if (ModelState.IsValid)
            {
                db.Bids.Add(bid);
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }

            ViewBag.BuyerID = new SelectList(db.Buyers, "ID", "FullName", bid.BuyerID);
            ViewBag.ItemID  = new SelectList(db.Items, "ID", "FullName", bid.ItemID);
            return(View(bid));
        }
Exemple #4
0
        public async Task <IActionResult> PostArticle()
        {
            try{
                var    body = Request.Body;
                string bodyStr;
                using (StreamReader reader
                           = new StreamReader(body, Encoding.UTF8, true, 1024, true))
                {
                    bodyStr = await reader.ReadToEndAsync();
                }

                var jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(bodyStr);

                var      newarticle = new Articles();
                Journals journal;

                try{
                    journal = _context.Journals.First(x => x.Name == jsonData["journal"].ToString());
                }
                catch (Exception e) {
                    journal      = new Journals();
                    journal.Name = jsonData["journal"].ToString();
                    _context.Add(journal);
                }

                newarticle.Journal = journal;
                newarticle.Summary = jsonData["summary"].ToString();
                newarticle.User    = jsonData["user"].ToString();
                newarticle.Date    = DateTime.Now.Year;
                _context.Add(newarticle);

                _context.SaveChanges();

                return(Ok());
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                return(BadRequest());
            }
        }