コード例 #1
0
        public ActionResult Edit([Bind(Include = "Id,Title,District,Street,Description,Size,Price,PictureId,DataHttpPostedFileBase")] AdModels adModels)
        {
            if (ModelState.IsValid)
            {
                Ad      ad      = db.Ad.Find(adModels.Id);
                Picture picture = db.Picture.Find(ad.PictureId);

                //mapping
                if (adModels.DataInHttpPostedFileBase != null)
                {
                    picture.Pic             = ConvertHttpPostedFileBaseToByteArray(adModels.DataInHttpPostedFileBase);
                    db.Entry(picture).State = EntityState.Modified;
                }

                ad.UserId      = int.Parse(Session["UserId"]?.ToString());
                ad.Id          = adModels.Id;
                ad.Title       = adModels.Title;
                ad.District    = adModels.District;
                ad.Street      = adModels.Street;
                ad.Description = adModels.Description;
                ad.Price       = adModels.Price;
                ad.Size        = adModels.Size;

                db.Entry(ad).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(View(adModels));
        }
コード例 #2
0
        public async Task <IHttpActionResult> Putproperty(int id, property property)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != property.id)
            {
                return(BadRequest());
            }

            db.Entry(property).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!propertyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Email,Password,UserRoleId")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserRoleId = new SelectList(db.UserRole, "Id", "Name", user.UserRoleId);
     return(View(user));
 }
コード例 #4
0
        public ActionResult Edit([Bind(Include = "Id,DataHttpPostedFileBase")] AdModels adModels)
        {
            if (ModelState.IsValid)
            {
                Picture picture = db.Picture.Find(adModels.Id);

                if (adModels.DataInHttpPostedFileBase != null)
                {
                    picture.Pic = ConvertHttpPostedFileBaseToByteArray(adModels.DataInHttpPostedFileBase);
                }

                db.Entry(picture).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(adModels));
        }