コード例 #1
0
        public ActionResult Edit(int id, HousingUpdate model)
        {
            HttpPostedFileBase file = Request.Files["ImageData"];

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

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

            var service = CreateHousingService();

            if (service.UpdateHousing(file, model))
            {
                TempData["SaveResult"] = "Housing was updated";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Housing could not be updated");
            return(View(model));
        }
コード例 #2
0
        // Housing Edit
        public ActionResult Edit(int id)
        {
            var service = CreateHousingService();
            var detail  = service.GetHousingDetail(id);
            var model   =
                new HousingUpdate
            {
                HousingId      = detail.HousingId,
                Name           = detail.Name,
                Address        = detail.Address,
                UnitsAvailable = detail.UnitsAvailable,
                AcceptVoucher  = detail.AcceptVoucher,
                SectionType    = detail.SectionType,
                Image          = detail.Image
            };

            return(View(model));
        }
コード例 #3
0
        public bool UpdateHousing(HttpPostedFileBase file, HousingUpdate model)
        {
            model.Image = ConvertToBytes(file);

            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Housings
                    .Single(e => e.HousingId == model.HousingId);
                // && e.OwnerId == _userId

                entity.Name           = model.Name;
                entity.Address        = model.Address;
                entity.UnitsAvailable = model.UnitsAvailable;
                entity.AcceptVoucher  = model.AcceptVoucher;
                entity.SectionType    = model.SectionType;
                entity.Image          = model.Image;

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #4
0
        // Update
        public int UpdateHousingById(HttpPostedFileBase file, int id, HousingUpdate newHousing)
        {
            newHousing.Image = ConvertToBytes(file);

            using (var ctx = new ApplicationDbContext())
            {
                Housing housing = ctx.Housings.Find(id);
                if (housing == null)
                {
                    return(2);
                }
                housing.Name           = newHousing.Name;
                housing.Address        = newHousing.Address;
                housing.UnitsAvailable = newHousing.UnitsAvailable;
                housing.AcceptVoucher  = newHousing.AcceptVoucher;
                housing.SectionType    = newHousing.SectionType;
                housing.Image          = newHousing.Image;
                if (ctx.SaveChanges() == 1)
                {
                    return(0);
                }
                return(1);
            }
        }