Beispiel #1
0
 public bool Save(MasterBlogModel blog)
 {
     if (CheckExisting(blog.ID))
     {
         return(Update(blog));
     }
     else
     {
         return(Add(blog));
     }
 }
Beispiel #2
0
        public ActionResult MasterBlog(MasterBlogModel masterBlogModel, HttpPostedFileBase Image, int?memberId)
        {
            var vtourDirectoryPath = Server.MapPath(string.Format("/BlogMedia/{0}/", memberId));

            if (!Directory.Exists(vtourDirectoryPath))
            {
                Directory.CreateDirectory(vtourDirectoryPath);
            }


            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];
                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(vtourDirectoryPath, fileName);
                        file.SaveAs(path);
                        masterBlogModel.Image = string.Format("/BlogMedia/{0}/{1}", memberId, fileName);
                    }
                }
                try
                {
                    var logComment = "Created Blog Title";
                    masterBlogModel.UserId = Convert.ToInt32(memberId);
                    mb.Save(masterBlogModel);
                    if (masterBlogModel.ID != 0)
                    {
                        logComment = "Updated Blog Title";
                    }
                    var logModel = new LogModel
                    {
                        UserId     = int.Parse(memberId.ToString()),
                        NodeId     = new MasterBlog().GetLatestMasterBlogId(),
                        LogHeader  = "Blog Post",
                        LogComment = logComment,
                        TableName  = "uSomeMasterBlog"
                    };
                    new LogHelper().Save(logModel);

                    TempData["MasterBlogCreationSuccessMessage"] = "Blog created Successfully";
                    return(RedirectToCurrentUmbracoPage());
                }
                catch (Exception ex)
                {
                    Log.ErrorLog("Error on creating blog title :: " + ex.Message);
                    @TempData["ErrorMessage"] = "failed";
                    return(CurrentUmbracoPage());
                }
            }
            return(CurrentUmbracoPage());
        }
Beispiel #3
0
 bool Update(MasterBlogModel blogModel)
 {
     try
     {
         var sql = string.Format("UPDATE [dbo].[uSomeMasterBlog] SET [title] = '{0}', [image] = '{1}', [isPublic] = '{2}',[category] ='{3}',[description]='{4}' WHERE id={5}",
                                 blogModel.Title, blogModel.Image, blogModel.IsPublic, blogModel.Category, blogModel.Description, blogModel.ID);
         _dataHelper.ExecuteNonQuery(sql);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #4
0
        bool Add(MasterBlogModel blogModel)
        {
            try
            {
                var sql = string.Format("INSERT INTO [dbo].[uSomeMasterBlog]([userId],[title],[image],[isPublic],[category],[description]) VALUES('{0}','{1}','{2}','{3}','{4}','{5}')",
                                        blogModel.UserId, blogModel.Title, blogModel.Image, blogModel.IsPublic, blogModel.Category, blogModel.Description);

                _dataHelper.ExecuteNonQuery(sql);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #5
0
        public MasterBlogModel GetMasterBlogByUserId(int userId)
        {
            var model = new MasterBlogModel();
            var sql   = "SELECT [id],[userId],[title],[image],[isPublic],[createdOn],[category],[description] FROM [dbo].[uSomeMasterBlog] WHERE userId ='" + userId + "'";

            foreach (var blog in GetMasterBlog(sql))
            {
                model.ID          = blog.ID;
                model.Image       = blog.Image;
                model.IsPublic    = blog.IsPublic;
                model.Title       = blog.Title;
                model.CreatedOn   = blog.CreatedOn;
                model.Category    = blog.Category;
                model.UserId      = blog.UserId;
                model.Description = blog.Description;
            }
            return(model);
        }
Beispiel #6
0
        private IList <MasterBlogModel> GetMasterBlog(string sqlText)
        {
            var blogList = new List <MasterBlogModel>();

            var dr = _dataHelper.ExecuteReader(sqlText);

            if (dr.HasRecords)
            {
                while (dr.Read())
                {
                    var blog = new MasterBlogModel();
                    blog.ID          = dr.GetInt("id");
                    blog.UserId      = dr.GetInt("userId");
                    blog.Title       = dr.GetString("title");
                    blog.Image       = dr.GetString("image");
                    blog.IsPublic    = dr.GetBoolean("isPublic");
                    blog.CreatedOn   = dr.GetDateTime("createdOn");
                    blog.Category    = dr.GetInt("category");
                    blog.Description = dr.GetString("description");
                    blogList.Add(blog);
                }
            }
            return(blogList);
        }