Beispiel #1
0
    //[ScriptMethod(UseHttpGet = false)]
    public static string delete(Guid userid, string websitename, string username)
    {
        string msg;

        // Response.Write(userid);
        // Response.Write(websitename);
        msg = "Hello";
        //  datalayer dl = new datalayer();
        MyProjectDataContext da = new MyProjectDataContext();
        var q = from a in da.Websites
                where a.UserId == userid && a.WebsiteName == websitename
                select a;
        int websiteid = GetWebsiteId(userid, username, websitename);
        var q1        = from b in da.WebsitePages
                        where b.WebsiteId == websiteid
                        select b;

        foreach (var o in q1)
        {
            da.WebsitePages.DeleteOnSubmit(o);   // removing foreign key references
        }
        foreach (var o in q)
        {
            da.Websites.DeleteOnSubmit(o);
        }

        try
        {
            //deleting name from drop down
            web_design_CreateWebsite ob = new web_design_CreateWebsite();
            ob.bind_website_ddl();
            //ob.ddl_select_website.Items.Remove(websitename);
            //--------------------------

            //deleting website folder and files

            string             subPath = "~/web-design/" + username + "/" + websitename + "/";
            System.Web.UI.Page p       = new System.Web.UI.Page(); //creating instance of object

            bool exists = System.IO.Directory.Exists(p.Server.MapPath(subPath));

            if (exists)
            {
                System.IO.Directory.Delete(p.Server.MapPath(subPath), true);
            }
            //deleting db
            DatabaseManagement dbManage = new DatabaseManagement();
            dbManage.DeleteDatabaseByWebsiteName(userid, websitename, username);
            //  end-------------
            da.SubmitChanges();

            msg = "success";
        }
        catch
        {
            msg = "error";
        }

        //   msg=dl.Delete_Website(userid, websitename);
        return(msg);
    }