Пример #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));
        }
    }
Пример #2
0
    public ReturnData AJAX_Updates(int idPostMedia, string title, string description)
    {
        try
        {
            DataClassesDataContext db        = new DataClassesDataContext();
            TBPostMedia            postMedia = db.TBPostMedias.Where(x => !x.Deflag && x.IDPostMedia == idPostMedia).FirstOrDefault();
            if (postMedia == null)
            {
                return(ReturnData.MessageFailed("Page Media not found", null));
            }
            postMedia.Title          = title;
            postMedia.Description    = description;
            postMedia.DateLastUpdate = DateTime.Now;
            db.SubmitChanges();

            return(ReturnData.MessageSuccess("Data updated successfully", null));
        }
        catch (Exception ex)
        {
            Class_Log_Error log = new Class_Log_Error();
            log.Insert(ex.Message, ex.StackTrace);

            return(ReturnData.MessageFailed(ex.Message, null));
        }
    }
Пример #3
0
    public ReturnData AJAX_Insert_Photo(int idPost, HttpPostedFile file)
    {
        try
        {
            using (DataClassesDataContext db = new DataClassesDataContext())
            {
                dynamic _post = Dynamic_GetDetail_Information(db, idPost);
                if (_post == null)
                {
                    return(ReturnData.MessageFailed("The requested resource does not exist.", null));
                }

                List <TBPostMedia> _renameFile = GetData_Photo_ByIDPost(db, idPost).ToList();
                for (int i = 0; i < _renameFile.Count; i++)
                {
                    string oldPhoto = _renameFile[i].MediaUrl;
                    _renameFile[i].MediaUrl = ((string)_post.Post_Title).ToLower().Replace(" ", "-") + "-" + (i + 1).ToString() + WITLibrary.ConvertCustom.GetExtention(oldPhoto);
                    if (OurClass.ImageExists(oldPhoto, "post"))
                    {
                        System.IO.File.Move(HttpContext.Current.Server.MapPath("~/assets/images/post/" + oldPhoto), HttpContext.Current.Server.MapPath("~/assets/images/post/" + _renameFile[i].MediaUrl));
                    }
                }

                int    fileSizeInBytes = file.ContentLength;
                string fileName        = file.FileName;
                string fileExtension   = System.IO.Path.GetExtension(fileName);

                TBPostMedia _newData = new TBPostMedia
                {
                    IDPost         = idPost,
                    MediaUrl       = ((string)_post.Post_Title).ToLower().Replace(" ", "-") + "-" + (_renameFile.Count() + 1).ToString() + fileExtension,
                    Active         = true,
                    DateInsert     = DateTime.Now,
                    DateLastUpdate = DateTime.Now,
                };

                db.TBPostMedias.InsertOnSubmit(_newData);
                db.SubmitChanges();
                if (_newData != null)
                {
                    file.SaveAs(HttpContext.Current.Server.MapPath("/assets/images/post/" + _newData.MediaUrl));
                    return(ReturnData.MessageSuccess(fileName + " for this product has been successfully uploaded.", null));
                }
                return(ReturnData.MessageFailed(fileName + " for this product failed to upload.", null));
            }
        }
        catch (Exception ex)
        {
            Class_Log_Error log = new Class_Log_Error();
            log.Insert(ex.Message, ex.StackTrace);

            return(ReturnData.MessageFailed(ex.Message, null));
        }
    }