Exemple #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")); }
        }
Exemple #2
0
 public ActionResult TurntoMain(int id, int AppId)
 {
     try
     {
         ApplicationDAO dao = new ApplicationDAO();
         Application    a   = dao.SearchById(AppId);
         if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId)
         {
             ImageDAO idao = new ImageDAO();
             Image    i    = idao.SearchById(id);
             a.ImageUrl = i.Url;
             dao.Update();
             return(RedirectToAction("EditApp", "Application", new { id = a.Id }));
         }
         return(RedirectToAction("Index", "Home"));
     }
     catch { return(RedirectToAction("Index", "Home")); }
 }