public ActionResult Edit(int id)
        {
            // var service = new RetailerService();
            var detail = _retailerService.GetRetailerById(id);
            var model  = new RetailerEdit()
            {
                Id                   = detail.RetailerId,
                Name                 = detail.Name,
                WebsiteUrl           = detail.WebsiteUrl,
                HasPhysicalLocations = detail.HasPhysicalLocations
            };

            return(View(model));
        }
예제 #2
0
        public IHttpActionResult Put(RetailerEdit retailer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateRetailerService();

            if (!service.UpdateRetailer(retailer))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool UpdateRetailer(RetailerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Retailers
                    .Single(e => e.RetailerId == model.RetailerId && e.OwnerId == _userID);

                entity.RetailerName    = model.RetailerName;
                entity.RetailerEin     = model.RetailerEin;
                entity.RetailerAddress = model.RetailerAddress;
                entity.RetailerEmail   = model.RetailerEmail;
                entity.RetailerPhone   = model.RetailerPhone;

                return(ctx.SaveChanges() == 1);
            }
        }
 public ActionResult Edit(int id, RetailerEdit model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (model.Id != id)
     {
         ModelState.AddModelError("", "Id Mismatch");
         return(View(model));
     }
     //var service = new RetailerService();
     if (_retailerService.UpdateRetailer(model))
     {
         TempData["SaveResult"] = "The retailer was updated.";
         return(RedirectToAction("Index"));
     }
     ModelState.AddModelError("", "Retailer could not be updated.");
     return(View(model));
 }
예제 #5
0
 public bool UpdateRetailer(RetailerEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         try
         {
             var entity = ctx.Retailers.Single(e => e.Id == model.Id);
             entity.Name                 = model.Name;
             entity.WebsiteUrl           = model.WebsiteUrl;
             entity.HasPhysicalLocations = model.HasPhysicalLocations;
             entity.ModifiedUtc          = DateTimeOffset.Now;
             return(ctx.SaveChanges() >= 1);
         }
         catch (Exception e)
         {
             Debug.Print("Exception thrown while looking for retailer");
             Debug.Print(e.Message);
             return(false);
         }
     }
 }