コード例 #1
0
        public ActionResult Create([Bind(Include = "id,region_id,complex_name,address,phone,facebook,instagram,edu_or_gym,photo,text,map_url")] our_complex our_complex, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                if (photo.ContentType == "image/jpeg" || photo.ContentType == "image/png" || photo.ContentType == "image/gif")
                {
                    //WebImage img = new WebImage(photo.InputStream);

                    DateTime now      = DateTime.Now;
                    string   fileName = now.ToString("yyyyMdHms") + Path.GetFileName(photo.FileName);
                    string   path     = Path.Combine(Server.MapPath("~/Uploads"), fileName);
                    photo.SaveAs(path);
                    //if (img.Width > 1000)
                    //    img.Resize(500, 500);
                    //img.Save(path);
                    our_complex.photo = fileName;
                    db.our_complex.Add(our_complex);
                    db.SaveChanges();
                }
                else
                {
                    ViewBag.region_id = new SelectList(db.regions, "id", "region1", our_complex.region_id);
                    ViewBag.Message   = "You can only jpg,png or gif file upload";
                    return(View());
                }
            }
            else
            {
                ViewBag.region_id = new SelectList(db.regions, "id", "region1", our_complex.region_id);
                ViewBag.Message   = "Errorrr";
                return(View());
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            our_complex our_complex = db.our_complex.Find(id);
            string      fullPath    = Request.MapPath("~/Uploads/" + our_complex.photo);

            if (System.IO.File.Exists(fullPath))
            {
                System.IO.File.Delete(fullPath);
            }
            db.our_complex.Remove(our_complex);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        // GET: Admins/our_complex_Crud/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            our_complex our_complex = db.our_complex.Find(id);

            if (our_complex == null)
            {
                return(HttpNotFound());
            }
            return(View(our_complex));
        }
コード例 #4
0
        // GET: Admins/our_complex_Crud/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            our_complex our_complex = db.our_complex.Find(id);

            if (our_complex == null)
            {
                return(HttpNotFound());
            }
            ViewBag.region_id = new SelectList(db.regions, "id", "region1", our_complex.region_id);
            return(View(our_complex));
        }
コード例 #5
0
        // GET: Complex
        public ActionResult Index(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            dynamic     mymodel    = new ExpandoObject();
            our_complex complex_id = db.our_complex.Find(id);

            mymodel.complexId = complex_id;
            mymodel.regions   = db.regions.ToList();
            mymodel.next      = db.our_complex.FirstOrDefault(n => n.id > complex_id.id);
            mymodel.prev      = db.our_complex.FirstOrDefault(p => p.id < complex_id.id);
            return(View(mymodel));
        }
コード例 #6
0
        // GET: Complex
        public ActionResult Index(int?id, int?regionID)
        {
            if (id == null || regionID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            dynamic     mymodel    = new ExpandoObject();
            our_complex complex_id = db.our_complex.Find(id);

            mymodel.complexId       = complex_id;
            mymodel.regions         = db.regions.ToList();
            mymodel.allKindergarten = db.our_complex.Where(c => c.region_id == complex_id.region_id && c.edu_or_gym == complex_id.edu_or_gym).ToList();


            return(View(mymodel));
        }
コード例 #7
0
        public ActionResult Edit(int id, [Bind(Include = "id,region_id,complex_name,address,phone,facebook,instagram,edu_or_gym,photo,text,map_url")] our_complex our_complex, string oldfile)
        {
            var gelensekil = HttpContext.Request.Files["photo"];

            if (gelensekil.FileName.Length > 0)
            {
                if (gelensekil.ContentType == "image/jpeg" || gelensekil.ContentType == "image/png" || gelensekil.ContentType == "image/gif")
                {
                    string fullPath = Request.MapPath("~/Uploads/" + oldfile);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                    DateTime now      = DateTime.Now;
                    string   fileName = now.ToString("yyyyMdHms") + Path.GetFileName(gelensekil.FileName);
                    string   newfile  = Path.Combine(Server.MapPath("~/Uploads"), fileName);
                    gelensekil.SaveAs(newfile);
                    our_complex.photo = fileName;
                }
                else
                {
                    ViewBag.region_id = new SelectList(db.regions, "id", "region1", our_complex.region_id);
                    ViewBag.Message   = "You can only jpg,png or gif file upload";
                    return(View());
                }
            }
            else
            {
                our_complex.photo = oldfile;
            }
            if (ModelState.IsValid)
            {
                db.Entry(our_complex).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(our_complex));
        }