Ejemplo n.º 1
0
    public ReturnData AJAX_Delete_Photo(int idPostMedia)
    {
        try
        {
            using (DataClassesDataContext db = new DataClassesDataContext())
            {
                TBPostMedia _deleteData = GetDetail_Photo(db, idPostMedia);
                if (_deleteData == null)
                {
                    return(ReturnData.MessageFailed("The requested resource does not exist.", null));
                }
                string _nameBefore = _deleteData.MediaUrl;

                db.TBPostMedias.DeleteOnSubmit(_deleteData);
                db.SubmitChanges();

                OurClass.DeleteFile(_deleteData.MediaUrl, "post");
                Dictionary <string, dynamic> _result = new Dictionary <string, dynamic>();
                _result.Add("Photos", Dynamic_GetData_Photo_ByIDPost(db, _deleteData.IDPost));
                return(ReturnData.MessageSuccess(_nameBefore + " has been successfully deleted.", _result));
            }
        }
        catch (Exception ex)
        {
            Class_Log_Error log = new Class_Log_Error();
            log.Insert(ex.Message, ex.StackTrace);

            return(ReturnData.MessageFailed(ex.Message, null));
        }
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        DataClassesDataContext db = new DataClassesDataContext();

        var delprods = db.TBProducts.Where(x => x.Deflag);
        int count    = 0;

        foreach (var item in delprods)
        {
            var imageprods = db.TBProduct_Photos.Where(x => x.IDProduct == item.IDProduct);
            var checkProds = db.TBProducts.Where(x => !x.Deflag && x.Name.ToLower() == item.Name.ToLower());
            if (checkProds == null)
            {
                Response.Write(item.Name + " (This Product is Still Active) <br/>");
            }
            else
            {
                foreach (var image in imageprods)
                {
                    Response.Write(image.Photo + "<br/>");
                    OurClass.DeleteFile(image.Photo, "product");
                    count++;
                    var combFoto = db.TBProduct_Combination_Photos.Where(x => x.IDProduct_Photo == image.IDProduct_Photo);
                    db.TBProduct_Combination_Photos.DeleteAllOnSubmit(combFoto);
                    db.SubmitChanges();
                    db.TBProduct_Photos.DeleteOnSubmit(image);
                    db.SubmitChanges();
                }
            }
        }
        Response.Write(count + " Image Product Deleted");
    }