예제 #1
0
        public ActionResult EditPhoto(int id, int PhotoId, HttpPostedFileBase img)
        {
            try
            {
                ApplicationDAO dao = new ApplicationDAO();
                Application    a   = dao.SearchById(id);
                if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId)
                {
                    ImageDAO idao = new ImageDAO();

                    Image i = idao.SearchById(PhotoId);
                    bool  b = false;
                    if (a.ImageUrl == i.Url)
                    {
                        b = true;
                    }
                    //Delete Photo in Server
                    string p = i.Url;
                    p = p.Replace("../../..", "..");
                    string fullPath = Request.MapPath(p);
                    idao.Remove(i);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                    //Upload
                    string filePath = Guid.NewGuid() + Path.GetExtension(img.FileName);
                    img.SaveAs(Path.Combine(Server.MapPath("~/media/app"), filePath));
                    Image im = new Image();
                    im.Url           = "../../../media/app/" + filePath;
                    im.UserId        = int.Parse(Session["Id"].ToString());
                    im.ApplicationId = a.Id;
                    idao.Add(im);

                    if (b)
                    {
                        a.ImageUrl = im.Url;
                        dao.Update();
                    }

                    return(RedirectToAction("EditApp", "Application", new { id = a.Id }));
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch { return(RedirectToAction("Index", "Home")); }
        }
예제 #2
0
 public ActionResult Remove(int id)
 {
     try
     {
         ApplicationDAO dao  = new ApplicationDAO();
         ImageDAO       idao = new ImageDAO();
         Application    a    = dao.SearchById(id);
         if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId)
         {
             try
             {
                 IList <Image> imgs = idao.SearchAppImages(a.Id);
                 foreach (var i in imgs)
                 {
                     string p = i.Url;
                     p = p.Replace("../../..", "../..");
                     string fullPath = Request.MapPath(p);
                     idao.Remove(i);
                     if (System.IO.File.Exists(fullPath))
                     {
                         System.IO.File.Delete(fullPath);
                     }
                 }
             }
             catch { }
             try
             {
                 string pa = a.Archive;
                 pa = pa.Replace("../../..", "../..");
                 string fullPathArch = Request.MapPath(pa);
                 if (System.IO.File.Exists(fullPathArch))
                 {
                     System.IO.File.Delete(fullPathArch);
                 }
             }
             catch { }
             dao.Remove(a);
             return(RedirectToAction("Summary", "Developer"));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
예제 #3
0
 public ActionResult RemoveImage(int id, int AppId)
 {
     try
     {
         ApplicationDAO dao = new ApplicationDAO();
         Application    a   = dao.SearchById(id);
         if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId)
         {
             ImageDAO idao = new ImageDAO();
             Image    i    = idao.SearchById(id);
             idao.Remove(i);
             return(RedirectToAction("EditApp", "Application", new { id = AppId }));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }