Ejemplo n.º 1
0
        public ActionResult Edit(int id, YarnEdit model)
        {
            return(View());

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.YarnId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateYarnService();

            if (service.UpdateYarn(model))
            {
                TempData["SaveResult"] = "Your yarn was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your yarn could not be updated.");
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var service = CreateYarnService();
            var detail  = service.GetYarnById(id);
            var model   =
                new YarnEdit
            {
                UserId         = detail.UserId,
                YarnId         = detail.YarnId,
                Color          = detail.Color,
                TotalYardage   = detail.TotalYardage,
                TotalWeight    = detail.TotalWeight,
                Fiber          = detail.Fiber,
                WherePurchased = detail.WherePurchased,
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public bool UpdateYarn(YarnEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Yarns
                    .Single(e => e.YarnId == model.YarnId && e.UserId == _userId);

                entity.UserId         = model.UserId;
                entity.YarnId         = model.YarnId;
                entity.Color          = model.Color;
                entity.TotalYardage   = model.TotalYardage;
                entity.TotalWeight    = model.TotalWeight;
                entity.WherePurchased = model.WherePurchased;

                return(ctx.SaveChanges() == 1);
            }
        }