Ejemplo n.º 1
0
        // GET: ProfileTbls/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProfileTbl profileTbl = db.ProfileTbls.Find(id);

            ViewBag.ExistingImg = profileTbl.P_Pic;
            if (profileTbl == null)
            {
                return(HttpNotFound());
            }
            ProfilesImg ViewInfo = new ProfilesImg
            {
                P_Id          = profileTbl.P_Id,
                P_Desc        = profileTbl.P_Desc,
                P_Name        = profileTbl.P_Name,
                P_Designation = profileTbl.P_Designation
            };

            ViewBag.ExistingFile = profileTbl.P_Pic;
            return(View(ViewInfo));
            //return View(profileTbl);
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            ProfileTbl profileTbl = db.ProfileTbls.Find(id);

            db.ProfileTbls.Remove(profileTbl);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        // GET: ProfileTbls/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProfileTbl profileTbl = db.ProfileTbls.Find(id);

            if (profileTbl == null)
            {
                return(HttpNotFound());
            }
            return(View(profileTbl));
        }
Ejemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "P_Id,P_Name,P_Desc,P_Designation, UploadedFile")] ProfilesImg profileTbl, string P_Pic)
        {
            //if (ModelState.IsValid)
            //{
            //    db.Entry(profileTbl).State = EntityState.Modified;
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}
            //return View(profileTbl);
            if (ModelState.IsValid)
            {
                string fn = "";

                ProfileTbl pt = new ProfileTbl
                {
                    P_Id          = profileTbl.P_Id,
                    P_Desc        = profileTbl.P_Desc,
                    P_Name        = profileTbl.P_Name,
                    P_Designation = profileTbl.P_Designation
                };

                if (profileTbl.UploadedFile != null)
                {
                    fn = profileTbl.UploadedFile.FileName.Substring(profileTbl.UploadedFile.FileName.LastIndexOf('\\') + 1);
                    fn = profileTbl.P_Id + "_" + fn;
                    string SavePath = System.IO.Path.Combine(Server.MapPath("~/Uploads/Pictures/Profiles/"), fn);
                    profileTbl.UploadedFile.SaveAs(SavePath);
                    pt.P_Pic = fn;
                }
                else
                {
                    pt.P_Pic = P_Pic;
                }

                db.Entry(pt).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(profileTbl));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "P_Id,P_Name,P_Desc,P_Designation, UploadedFile")] ProfilesImg profileTbl)
        {
            if (ModelState.IsValid)
            {
                ProfileTbl pt = new ProfileTbl
                {
                    P_Id          = profileTbl.P_Id,
                    P_Name        = profileTbl.P_Name,
                    P_Designation = profileTbl.P_Designation,
                    P_Desc        = profileTbl.P_Desc,
                };

                if (profileTbl.UploadedFile != null)
                {
                    string fn = profileTbl.UploadedFile.FileName.Substring(profileTbl.UploadedFile.FileName.LastIndexOf('\\') + 1);
                    Random rd = new Random(DateTime.Today.Day);
                    fn = rd.Next(300, 800) + "_" + fn;
                    string SavePath = System.IO.Path.Combine(Server.MapPath("~/Uploads/Pictures/Profiles/"), fn);
                    profileTbl.UploadedFile.SaveAs(SavePath);
                    pt.P_Pic = fn;
                }


                db.ProfileTbls.Add(pt);
                db.SaveChanges();

                ViewData["FileName"] = pt.P_Pic;
                return(RedirectToAction("Index"));
            }

            /*if (ModelState.IsValid)
             * {
             *  db.ProfileTbls.Add(profileTbl);
             *  db.SaveChanges();
             *  return RedirectToAction("Index");
             * }*/

            return(View(profileTbl));
        }