예제 #1
0
        public ActionResult Remove(string[] fileNames)
        {
            PictureRepository picRep = new PictureRepository();
            int NewPicID = picRep.GetLastPictureId(Convert.ToInt32(HttpContext.Session["ClientId"]));

            // The parameter of the Remove action must be called "fileNames"
            foreach (var fullName in fileNames)
            {
                var fileName = Path.GetFileName(fullName);
                var extention = fileName.Substring(fileName.IndexOf('.'));
                var newfilename = NewPicID.ToString() + extention;

                // Check if Path exsits
                string serverpath = Server.MapPath("~/Images/Client/" + HttpContext.Session["ClientId"].ToString() + "/Ads");
                if (!Directory.Exists(serverpath))
                {
                    Directory.CreateDirectory(serverpath);
                }

                var physicalPath = Path.Combine(Server.MapPath("~/Images/Client/" + HttpContext.Session["ClientId"].ToString() + "/Ads"), newfilename);

                // TODO: Verify user permissions
                if (System.IO.File.Exists(physicalPath))
                {
                    // The files are not actually removed in this demo
                    System.IO.File.Delete(physicalPath);

                    picRep.RemovePicture(NewPicID);
                }
            }
            // Return an empty string to signify success
            return Content("");
        }
예제 #2
0
        public ActionResult _DeleteEvent(int id)
        {
            PictureRepository picRep = new PictureRepository();
            Event ins = EventRep.GetEvent(id);
            if (ins.PictureId != 0)
            {
                //...Get Picture...
                Picture pic = picRep.GetPicture(ins.PictureId);
                string path = pic.PicUrl.Substring(pic.PicUrl.IndexOf("/Images/") + 8);
                path = path.Replace('/', '\\');
                var finalpath = Path.Combine(Server.MapPath("~/Images"), path);
                System.IO.File.Delete(finalpath);
                bool picrem = picRep.RemovePicture(ins.PictureId);
            }

            bool ins2 = EventRep.RemoveEvent(id);

            //...Notify...
            string regIds = AppRep.GetAllRegIds(Convert.ToInt32(HttpContext.Session["ClientId"]));
            if (!regIds.Equals(""))
            {
                comrep.NewUpdateData(regIds, "CMD_DELEVENT", id.ToString());
            }

            //...Repopulate Grid...
            List<Event> lst = new List<Event>();
            lst = EventRep.GetListEvent(Convert.ToInt32(HttpContext.Session["ClientId"]));
            return View(new GridModel(lst));
        }