public IActionResult CreateWidget(string name)
        {
            Models.Widget widget = new Models.Widget();
            widget.Name = name;
            db.CreateWidget(widget);

            return(new ObjectResult(widget));
        }
 public async Task SaveWidget(Widget widget)
 {
     using (var db = new AppDbContext())
     {
         db.Widgets.Add(widget);
         await db.SaveChangesAsync();
     }
 }
Example #3
0
        public Guid CreateWidget(string name, float price, Guid userId)
        {
            var user = _repoU.GetUser(userId);
            var widget = new Widget()
            {
                Name = name,
                Price = price,
                User = user
            };

            _repoW.SaveWidget(widget);
            return widget.Id;
        }
 public ActionResult Create(Widget newWidget)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _case.CreateWidget(newWidget.Name, newWidget.Price);
             return RedirectToAction("Index");
         }
         else
         {
             return View(newWidget);
         }
     }
     catch
     {
         return View(newWidget);
     }
 }
 public ActionResult Create(Widget newWidget)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _case.CreateWidget(newWidget.Name, newWidget.Price, newWidget.User.Id);
             return RedirectToAction("Index");
         }
         else
         {
             return View(newWidget);
         }
     }
     catch (Exception e)
     {
         _log.Error(e.Message);
         return View(newWidget);
     }
 }
Example #6
0
 public void UpdateWidget(Widget widget)
 {
     _repo.SaveWidget(widget);
 }
Example #7
0
 public Guid CreateWidget(string name, float price)
 {
     var w = new Widget {Name = name, Price = price};
     _repo.SaveWidget(w);
     return w.Id;
 }
 public ActionResult Edit(Widget widget)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _case.UpdateWidget(widget);
             return RedirectToAction("Index");
         }
         else
         {
             return View(widget);
         }
     }
     catch
     {
         return View(widget);
     }
 }