public ActionResult EditProject1([Bind(Include = "ID,PropertyName,Avatar,Images,PropertyType_ID,Content,Street_ID,Ward_ID,District_ID,Price,UnitPrice,Area,BedRoom,BathRoom,PackingPlace,UserID,Created_at,Create_post,Status_ID,Note,Updated_at,Sale_ID")] PROPERTY model) { var pro = db.PROPERTies.Find(model.ID); pro.PropertyName = model.PropertyName; pro.Avatar = model.Avatar; pro.Images = model.Images; pro.PropertyType_ID = model.PropertyType_ID; pro.Content = model.Content; pro.Street_ID = model.Street_ID; pro.Ward_ID = model.Ward_ID; pro.District_ID = model.District_ID; pro.Price = model.Price; pro.UnitPrice = model.UnitPrice; pro.Area = model.Area; pro.BedRoom = model.BedRoom; pro.BathRoom = model.BathRoom; pro.PackingPlace = model.PackingPlace; pro.UserID = model.UserID; pro.Created_at = model.Created_at; pro.Create_post = model.Create_post; pro.Status_ID = model.Status_ID; pro.Note = model.Note; pro.Updated_at = DateTime.Now; pro.Sale_ID = model.Sale_ID; pro.PROPERTY_FEATURE = model.PROPERTY_FEATURE; db.Entry(pro).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditProject1(PROPERTY model, HttpPostedFileBase Avatar, List <string> chk1, List <HttpPostedFileBase> images) { PROPERTY pro = db.PROPERTies.Find(model.ID); var ftpr = db.PROPERTY_FEATURE.Where(x => x.Property_ID == model.ID).ToList(); var imag = db.PROPERTY_IMAGE.Where(x => x.Property_ID == model.ID); db.PROPERTY_FEATURE.RemoveRange(ftpr); db.PROPERTY_IMAGE.RemoveRange(imag); if (Avatar != null) { string avatar = ""; if (Avatar.ContentLength > 0) { var filename = Path.GetFileName(Avatar.FileName); var path = Path.Combine(Server.MapPath("~/Images/"), filename); Avatar.SaveAs(path); avatar = filename; } pro.Avatar = avatar; } foreach (HttpPostedFileBase img in images) { if (img != null) { if (img.ContentLength > 0) { var filename = Path.GetFileName(img.FileName); var path = Path.Combine(Server.MapPath("~/Images/"), filename); img.SaveAs(path); PROPERTY_IMAGE ppti = new PROPERTY_IMAGE(); ppti.Image = filename; ppti.Property_ID = model.ID; db.PROPERTY_IMAGE.Add(ppti); } else { db.SaveChanges(); } } else { db.SaveChanges(); } } foreach (var fe in chk1) { PROPERTY_FEATURE profe = new PROPERTY_FEATURE(); profe.Feature_ID = db.FEATUREs.SingleOrDefault(x => x.FeatureName == fe).ID; profe.Property_ID = pro.ID; db.PROPERTY_FEATURE.Add(profe); } pro.PropertyName = model.PropertyName; pro.PropertyType_ID = model.PropertyType_ID; pro.Content = model.Content; pro.Street_ID = model.Street_ID; pro.Ward_ID = model.Ward_ID; pro.District_ID = model.District_ID; pro.Price = model.Price; pro.UnitPrice = model.UnitPrice; pro.Area = model.Area; pro.BedRoom = model.BedRoom; pro.BathRoom = model.BathRoom; pro.PackingPlace = model.PackingPlace; pro.Status_ID = model.Status_ID; pro.Note = model.Note; pro.Updated_at = DateTime.Now; pro.Sale_ID = int.Parse(Session["UserID"].ToString()); db.Entry(pro).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }