コード例 #1
0
 public ActionResult Create([Bind(Include = "ID,Name,BuildingType,Dimension,Description,Price")] HouseDesign houseDesign, HttpPostedFileBase upload)
 {
     if (ModelState.IsValid)
     {
         if (upload != null && upload.ContentLength > 0)
         {
             var avatar = new File
             {
                 FileName    = System.IO.Path.GetFileName(upload.FileName),
                 FileType    = FileType.Avatar,
                 ContentType = upload.ContentType
             };
             using (var reader = new System.IO.BinaryReader(upload.InputStream))
             {
                 avatar.Content = reader.ReadBytes(upload.ContentLength);
             }
             houseDesign.Files = new List <File> {
                 avatar
             };
         }
         db.HouseDesigns.Add(houseDesign);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(houseDesign));
 }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            HouseDesign houseDesign = db.HouseDesigns.Find(id);

            db.HouseDesigns.Remove(houseDesign);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "ID,Name,BuildingType,Dimension,Description,Price")] HouseDesign houseDesign)
 {
     if (ModelState.IsValid)
     {
         db.Entry(houseDesign).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(houseDesign));
 }
コード例 #4
0
        // GET: HouseDesign/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HouseDesign houseDesign = db.HouseDesigns.Include(s => s.Files).SingleOrDefault(s => s.ID == id);

            if (houseDesign == null)
            {
                return(HttpNotFound());
            }
            return(View(houseDesign));
        }
コード例 #5
0
        // GET: HouseDesign/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HouseDesign houseDesign = db.HouseDesigns.Find(id);

            if (houseDesign == null)
            {
                return(HttpNotFound());
            }
            return(View(houseDesign));
        }