Пример #1
0
        public ActionResult Edit(SanaatanResource model)
        {
            TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
            DateTime     indianTime  = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);

            if (ModelState.IsValid)
            {
                string             fdel  = "";
                string             Fname = "";
                string             path  = "";
                HttpPostedFileBase pb    = Request.Files["image"];
                if (pb != null && pb.ContentLength > 0)
                {
                    path = Server.MapPath("~/Content/UploadedImages/Sanaatan");
                    fdel = System.IO.Path.Combine(path, model.Image);
                    System.IO.File.Delete(fdel);
                    Fname = DateTime.Now.Date.ToString("yyyyMMddHHmmssfff") + System.IO.Path.GetFileName(pb.FileName);
                    pb.SaveAs(System.IO.Path.Combine(path, Fname));
                    model.Image = Fname;
                }

                db._SanaatanResource.Add(model);
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("List"));
            }

            return(View());
        }
Пример #2
0
        public ActionResult View(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SanaatanResource m = db._SanaatanResource.Find(id);

            if (m == null)
            {
                return(HttpNotFound());
            }
            return(View(m));
        }
Пример #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            SanaatanResource m    = db._SanaatanResource.Find(id);
            string           fdel = m.Image;

            string path = "";

            path = Server.MapPath("~/Content/UploadedImages/Sanaatan");
            fdel = System.IO.Path.Combine(path, fdel);
            System.IO.File.Delete(fdel);

            db._SanaatanResource.Remove(m);
            db.SaveChanges();

            return(RedirectToAction("List"));
        }
Пример #4
0
        public ActionResult Create(SanaatanResource js)
        {
            if (ModelState.IsValid)
            {
                string             Fname = "";
                string             path  = "";
                HttpPostedFileBase pb    = Request.Files["image"];
                if (pb != null && pb.ContentLength > 0)
                {
                    Fname = DateTime.Now.ToString("yyyyMMddHHmmssfff") + System.IO.Path.GetFileName(pb.FileName);
                    path  = Server.MapPath("~/Content/UploadedImages/Sanaatan");
                    pb.SaveAs(System.IO.Path.Combine(path, Fname));

                    js.Image = Fname;
                }
                db._SanaatanResource.Add(js);
                db.SaveChanges();
                return(RedirectToAction("List"));
            }
            return(RedirectToAction("Index", "Home"));
        }