public async Task <IActionResult> CreateBlog([Bind("BlogTitle,BlogText,BlogCategory,CategoryName")] BlogCategories blogs, IFormFile file, string blogStatus) { //check if image is valid ValidImageUpload(file, "Blog"); if (blogStatus == "CreateBlog") { if (blogs.BlogCategory == Guid.Empty) { ModelState.AddModelError("CategoryName", "Add or select a category before creating a blog"); } if (ModelState.IsValid) { //create new blog object Blogs newBlog = new Blogs(); //give new blog a unique id newBlog.BlogId = Guid.NewGuid(); newBlog.BlogTitle = blogs.BlogTitle; newBlog.BlogText = blogs.BlogText; newBlog.BlogCategory = blogs.BlogCategory; //add image to image folder if employee uploaded one if (file != null) { //Add to Database Images image = await TTLAddImage(file); _context.Add(image); await _context.SaveChangesAsync(); newBlog.BlogImageId = image.ImageId; } //set blog upload date newBlog.BlogUploadDate = DateTime.Now; newBlog.BlogEditDate = DateTime.Now; _context.Add(newBlog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(AllBlogs))); } } //Add New Category else { if (ModelState.IsValid) { Categories category = new Categories(); category.CategoryId = Guid.NewGuid(); category.CategoryName = blogs.CategoryName; _context.Add(category); await _context.SaveChangesAsync(); blogs.BlogCategory = category.CategoryId; } } ViewData["Categories"] = TTLCategoryList(blogs.BlogCategory); return(View(blogs)); }
public void RemoveBlog() { if (CurrentBlog != null) { Blogs.Remove(CurrentBlog); } }
static void Main(string[] args) { using (var db = new BloggingContext()) { // Create and save a new Blog Console.Write("Enter a name for a new Blog: "); var name = Console.ReadLine(); var blog = new Blogs { Name = name }; db.Blogs.Add(blog); db.SaveChanges(); // Display all Blogs from the database var query = from b in db.Blogs orderby b.Name select b; Console.WriteLine("All blogs in the database:"); foreach (var item in query) { Console.WriteLine(item.Name); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }
public async Task <IActionResult> Edit(int id, [Bind("BlogId,Url")] Blogs blogs) { if (id != blogs.BlogId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(blogs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogsExists(blogs.BlogId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(blogs)); }
/// <summary> /// Obtiene el número de elementos no leÃdos /// </summary> public int GetNumberNotRead() { // Calcula el número de elementos no leÃdos NumberNotRead = Blogs.GetNumberNotRead() + Folders.GetNumberNotRead(); // Y devuelve el valor return(NumberNotRead); }
public string UpdateData(Blogs blog) { SqlConnection con = null; string result = ""; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString()); SqlCommand cmd = new SqlCommand("proc_CRUD_Blogs_2", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TITLE", blog.Title); cmd.Parameters.AddWithValue("@Description_Short", blog.DescriptionShort); cmd.Parameters.AddWithValue("@Detail", blog.Detail); cmd.Parameters.AddWithValue("@Image", blog.Image); cmd.Parameters.AddWithValue("@Category", blog.Category); cmd.Parameters.AddWithValue("@Location", blog.Locations); cmd.Parameters.AddWithValue("@Public", blog.Publics); cmd.Parameters.AddWithValue("@Date_Public", blog.DatePublic); cmd.Parameters.AddWithValue("@ID", blog.Id); cmd.Parameters.AddWithValue("@Query", UPDATE); con.Open(); result = cmd.ExecuteScalar().ToString(); return(result); } catch { return(result = ""); } finally { con.Close(); } }
public ActionResult DeleteConfirmed(int id) { Blogs blog = db.Blogs.Find(id); var comments = db.Comments.Where(c => c.BlogsId == id); foreach (var item in comments) { db.Comments.Remove(item); } var liked = db.Liked.Where(l => l.BlogsId == id); foreach (var item in liked) { db.Liked.Remove(item); } var attaches = db.Attach.Where(a => a.BlogsId == id); foreach (var item in attaches) { FileInfo fi = new FileInfo(Server.MapPath(item.Src)); fi.Delete(); db.Attach.Remove(item); } db.Blogs.Remove(blog); db.SaveChanges(); AddChangelog("DeleteBlog", WebSecurity.CurrentUserId, id); return(RedirectToAction("Index")); }
public ActionResult FeatureBlog(int id) { Blogs blog = db.Blogs.Find(id); var list = db.Featured.ToList(); if (list.Count < 6) { FeaturedList fl = new FeaturedList { BlogsId = blog.BlogsId }; db.Featured.Add(fl); } else { FeaturedList fl = list[0]; fl.blog.IsFeatured = false; FeaturedList newfl = new FeaturedList { BlogsId = blog.BlogsId }; db.Entry(fl.blog); db.Featured.Remove(fl); db.Featured.Add(newfl); } blog.IsFeatured = true; db.Entry(blog); db.SaveChanges(); return(RedirectToAction("Details", new { id = id })); }
public async Task <IActionResult> Ekle(Blogs blog, IFormFile Image) { var myBlog = new Blogs(); if (Image == null || Image.Length == 0) { return(RedirectToAction("Error", "Yonetim")); } string newImage = Guid.NewGuid().ToString() + Image.FileName; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img\\bloglar", newImage); using (var stream = new FileStream(path, FileMode.Create)) { await Image.CopyToAsync(stream); } myBlog.Fotograf = newImage; myBlog.Baslik = blog.Baslik; myBlog.Yazar = blog.Yazar; myBlog.EklenmeTarihi = blog.EklenmeTarihi; myBlog.Icerik = blog.Icerik; blogOperations.Add(myBlog); return(RedirectToAction("Index")); }
/// <summary> /// Comprueba si se puede ejecutar una acción /// </summary> protected override bool CanExecuteAction(string action, object parameter) { switch (action) { case nameof(FirstPageCommand): case nameof(PreviousPageCommand): return(ActualPage > 1); case nameof(LastPageCommand): case nameof(NextPageCommand): return(ActualPage < Pages); case nameof(DeleteCommand): return(SelectedEntry != null || (SelectedEntry == null && Blogs.GetNumberNotRead() == 0 && Entries.Count > 0)); case nameof(MarkAsReadCommand): case nameof(MarkAsNotReadCommand): case nameof(MarkAsInterestingCommand): return(SelectedEntry != null); case nameof(ExportEntriesCommand): case nameof(PlayCommand): return(true); default: return(false); } }
public ActionResult SaveBlog(Blogs blogs, List <IFormFile> files) { var adminId = HttpContext.Session.GetInt32("Id"); if (adminId.HasValue) { blogs.AdminId = adminId.Value; var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "VehicleImages"); foreach (var file in files) { if (file.Length > 0) { var filePath = Path.Combine(uploads, file.FileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { file.CopyTo(fileStream); } blogs.Image = file.FileName; } } blogs.CreatedDate = blogs.Id > 0 ? blogs.CreatedDate : DateTime.Now; _context.Entry(blogs).State = blogs.Id > 0 ? EntityState.Modified : EntityState.Added; _context.SaveChanges(); return(RedirectToAction("Blogs")); } else { return(RedirectToAction("LogIn", "Admin")); } }
public async Task <IActionResult> Update(Blogs blogs, int?id) { Blogs viewBlog = _context.Blogs.Include(b => b.Tags).Include(b => b.latestPosts) .FirstOrDefault(b => b.id == id && b.IsDeleted == false); if (blogs.Photo != null) { if (!blogs.Photo.IsImage()) { ModelState.AddModelError("", "Please select image type"); return(View(viewBlog)); } if (!blogs.Photo.MaxSize(250)) { ModelState.AddModelError("", "Image size must be less than 250kb"); return(View(viewBlog)); } string folder = Path.Combine("assets", "img", "blog"); string fileName = await blogs.Photo.SaveImageAsync(_env.WebRootPath, folder); viewBlog.Image = fileName; } viewBlog.Description = blogs.Description; blogs.IsDeleted = false; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
private void DeleteBlog() { if (Repository.Delete(SelectedBlog)) { Blogs.Remove(SelectedBlog); } }
public bool AddNew(Blogs NewPodcast, string InserUser) { bool rpta; try { DynamicParameters Parm = new DynamicParameters(); Parm.Add("@InsertUser", InserUser); Parm.Add("@Title", NewPodcast.Title.Trim()); Parm.Add("@KeyWord", NewPodcast.KeyWord.Trim()); Parm.Add("@Description", NewPodcast.Description.Trim()); Parm.Add("@Banner", NewPodcast.BannerPath); Parm.Add("@MinisterID", NewPodcast.MinisterID); Parm.Add("@InsertDate", NewPodcast.InsertDate); SqlCon.Open(); SqlCon.Execute("[adm].[uspAddBlog]", Parm, commandType: CommandType.StoredProcedure); rpta = true; } catch (Exception ex) { throw ex; } if (SqlCon.State == ConnectionState.Open) SqlCon.Close(); return rpta; }
static void Main(string[] args) { using (var context = new BloggingContext()) { // Blog instances are created via parameterized ctor foreach (var blog in context.Blogs) { Console.WriteLine($"{blog.Id}\t{blog.Name}"); } Console.ReadKey(); // ID can be assigned by Entity Framework // but not by us - Id has private setter var newBlog = new Blogs("New blog"); context.Blogs.Add(newBlog); context.SaveChanges(); Console.WriteLine("New blog ID: " + newBlog.Id); context.Blogs.Remove(newBlog); context.SaveChanges(); Console.ReadKey(); // injecting IEntityType to get metadata about type var post = context.Posts.Find(3); Console.WriteLine(post.EntityType.Name); Console.ReadKey(); } }
/// <summary> /// Inhabilita o habilita una entrada de entrada /// </summary> /// <param name="slug"></param> /// <returns></returns> public ApiCallResult CambiarEstadoEntrada(string slug) { try { #region Validaciones Blogs blog = this.repository.ObtenerSlug(slug); if (blog is null) { throw new NegocioExecption($"No existe ninguna entrada con este SLUG {slug}", 202); } #endregion blog.Estado = !blog.Estado; this.repository.ActualizarEntrada(blog); return(new ApiCallResult { Estado = true, Mensaje = "Video inhabilitado exitosamente" }); } catch (NegocioExecption) { throw; } catch (Exception) { throw; } }
private void DeserializeStoreData(IsolatedStorageFile isoStore) { if (!isoStore.FileExists(STORE_FILENAME)) { return; } using (IsolatedStorageFileStream isoStream = isoStore.OpenFile(STORE_FILENAME, FileMode.Open)) { XmlSerializer serializer = new XmlSerializer(typeof(StoreData)); StoreData result = serializer.Deserialize(isoStream) as StoreData; if ("" != result.Xmlrpc) { if (null != Blogs && 0 < Blogs.Count) { CurrentBlog = Blogs.Single(b => b.Xmlrpc == result.Xmlrpc); } } CurrentComment = result.Comment; CurrentPostListItem = result.PostListItem; CurrentPageListItem = result.PageListItem; CurrentPost = result.Post; } }
public Task <Blogs> CreateBlogAsync(BlogDTO newBlog, IEnumerable <String> BlogCatagories) { try { Blogs objBlogs = new Blogs(); objBlogs.BlogId = 0; objBlogs.BlogContent = newBlog.BlogContent; objBlogs.BlogDate = newBlog.BlogDate; objBlogs.BlogSummary = newBlog.BlogSummary; objBlogs.BlogTitle = newBlog.BlogTitle; objBlogs.BlogUserName = newBlog.BlogUserName; objBlogs.BlogContent = newBlog.BlogContent; if (BlogCatagories == null) { objBlogs.BlogCategory = null; } else { objBlogs.BlogCategory = GetSelectedBlogCategories(newBlog, BlogCatagories); } _context.Blogs.Add(objBlogs); _context.SaveChanges(); return(Task.FromResult(objBlogs)); } catch (Exception ex) { DetachAllEntities(); throw ex; } }
public int InsertBlog(Blogs objcust) { SqlConnection con = null; int result; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString()); SqlCommand cmd = new SqlCommand("InsertBlog", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", objcust.Title); cmd.Parameters.AddWithValue("@Des", objcust.Des); cmd.Parameters.AddWithValue("@Detail", objcust.Detail); cmd.Parameters.AddWithValue("@Category", objcust.Category); cmd.Parameters.AddWithValue("@IsPublished", objcust.IsPublished); cmd.Parameters.AddWithValue("@DatePublic", objcust.DatePublic); cmd.Parameters.AddWithValue("@Thumb", objcust.Thumb); con.Open(); result = Convert.ToInt32(cmd.ExecuteScalar().ToString()); return(result); } catch (Exception exp) { Console.WriteLine(exp.Message); return(0); } finally { con.Close(); } }
public int UpdateBlog(Blogs blog) { SqlConnection con = null; int result; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString()); SqlCommand cmd = new SqlCommand("UpdateBlog", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", blog.Id); cmd.Parameters.AddWithValue("@Title", blog.Title); cmd.Parameters.AddWithValue("@Des", blog.Des); cmd.Parameters.AddWithValue("@Detail", blog.Detail); cmd.Parameters.AddWithValue("@Category", blog.Category); cmd.Parameters.AddWithValue("@IsPublished", blog.IsPublished); cmd.Parameters.AddWithValue("@DatePublic", blog.DatePublic); //cmd.Parameters.AddWithValue("@Position", blog.Position); cmd.Parameters.AddWithValue("@Thumb", blog.Thumb); con.Open(); result = Convert.ToInt32(cmd.ExecuteScalar().ToString()); return(result); } catch { return(0); } finally { con.Close(); } }
/// <summary> /// Guarda el comentario de un post en especifico /// </summary> /// <param name="comentarioDto"></param> /// <returns></returns> public ApiCallResult GuardarComentario(ComentarioSavedDto comentarioDto) { try { Blogs blog = this.blogRepository.ObtenerSlug(comentarioDto.Slug); if (blog is null) { throw new Exception("No existe la entrada"); } Comentarios comentario = mapper.Map <Comentarios>(comentarioDto); comentario.Idblog = blog.Idblog; comentario.Fechacreaciion = DateTime.Now; this.blogRepository.GuardarComentario(comentario); return(new ApiCallResult { Estado = true, Mensaje = "Comentario guardado" }); } catch (Exception e) { return(new ApiCallResult { Estado = false, Mensaje = $"Error en {e.Message}" }); } }
public ActionResult Release(int?id) { if (BLLSession.UserInfoSessioin == null) { Response.Redirect("/Account/Login?href=/ManageBlog/Release"); return(null); } Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("blogTag", GetDataHelper.GetAllTag(BLLSession.UserInfoSessioin.UserId).ToList()); dic.Add("blogType", DataCache.GetAllType().Where(t => t.UserId == BLLSession.UserInfoSessioin.UserId).ToList()); Blogs blog = null; if (null != id) { blog = new Blogs(); BlogsBLL blogbll = new BlogsBLL(); blog = blogbll.GetList(t => t.BlogId == id && (t.UserId == BLLSession.UserInfoSessioin.UserId || BLLSession.UserInfoSessioin.UserName == admin)).FirstOrDefault(); if (blog == null) { return(View("Error")); } } dic.Add("blog", blog); return(View(dic)); }
public static bool EditBlog(Blogs blog, string title, string text) { Blogs newblog = new Blogs(title, text); newblog.ID = blog.ID; return(_blogsLogic.EditBlog(newblog)); }
public IActionResult GetBlogPosts([FromQuery] string tag) { try { var posts = _repositoryBlogPost.GetByTag(tag).ToList(); if (posts.Count == 0) { return(NotFound("There is no posts with that tag")); } var blogPosts = new Blogs { BlogPosts = new List <BlogPost>() }; foreach (var post in posts) { blogPosts.BlogPosts.Add(_repositoryBlogPost.GetBySlug(post)); } blogPosts.PostsCount = blogPosts.BlogPosts.Count; return(Ok(blogPosts)); } catch (Exception ex) { _logger.LogError(ex.Message, ex); return(StatusCode(500)); } }
public WriteBlogModel(IBlogData blogData, IUserData userData, IWebHostEnvironment hostEnvironment) { this.blogData = blogData; this.userData = userData; this.hostEnvironment = hostEnvironment; writeBlog = new Blogs(); }
//Insert blogs public int CreateBlog(Blogs model) { int retVal = 0; string connString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection sqlConn = new SqlConnection(connString)) { using (SqlCommand cmd = new SqlCommand("dbo.Blogs_Insert", sqlConn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", model.Title); cmd.Parameters.AddWithValue("@Content", model.Content); cmd.Parameters.AddWithValue("@Image", model.Image); SqlParameter parm = new SqlParameter(); parm.ParameterName = "@Id"; parm.SqlDbType = System.Data.SqlDbType.Int; parm.Direction = System.Data.ParameterDirection.Output; cmd.Parameters.Add(parm); sqlConn.Open(); cmd.ExecuteNonQuery(); retVal = (int)cmd.Parameters["@id"].Value; } } return(retVal); }
//Get all blogs public List <Blogs> GetBlogs() { List <Blogs> blogList = new List <Blogs>(); string connString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection sqlConn = new SqlConnection(connString)) { using (SqlCommand cmd = new SqlCommand("dbo.Blogs_SelectAll", sqlConn)) { sqlConn.Open(); SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); while (reader.Read()) { Blogs b = new Blogs(); b.Id = reader.GetInt32(0); b.Title = reader.GetString(1); b.Content = reader.GetString(2); b.Image = reader.GetString(3); blogList.Add(b); } } } return(blogList); }
public string InsertData(Blogs blog) { SqlConnection con = null; string result = ""; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString()); SqlCommand cmd = new SqlCommand("proc_CRUD_Blogs_2", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TITLE", blog.Title); cmd.Parameters.AddWithValue("@DESCRIPTION_SHORT", blog.DescriptionShort); cmd.Parameters.AddWithValue("@DETAIL", blog.Detail); cmd.Parameters.AddWithValue("@IMAGE", blog.Image); cmd.Parameters.AddWithValue("@CATEGORY", blog.Category); cmd.Parameters.AddWithValue("@LOCATION", blog.Locations); cmd.Parameters.AddWithValue("@PUBLICS", blog.Publics); cmd.Parameters.AddWithValue("@QUERY", INSERT); con.Open(); result = cmd.ExecuteScalar().ToString(); return(result); } catch (Exception ex) { return(result = ""); } finally { con.Close(); } }
public override int GetHashCode() { unchecked { return(((Blogs != null ? Blogs.GetHashCode() : 0) * 397) ^ (Posts != null ? Posts.GetHashCode() : 0)); } }
public IActionResult OnPost() { var Username = HttpContext.Session.GetString("username"); if (string.IsNullOrEmpty(Username)) { return(RedirectToPage("/Index")); } SingleUserData = userData.GetByUserName(Username); writeBlog.Users = SingleUserData; ; if (BlogPicture != null) { writeBlog.BlogImage = UploadedPicture(BlogPicture, SingleUserData.UserName); } var newBlog = new Blogs() { Users = writeBlog.Users, BlogTitle = writeBlog.BlogTitle, BlogDescription = writeBlog.BlogDescription, Blogcontent = writeBlog.Blogcontent, BlogDate = DateTime.Now.Date, BlogImage = writeBlog.BlogImage }; bool res = blogData.AddBlog(newBlog); if (res) { blogData.Commit(); return(RedirectToPage("/User/Dashboard", new { urlname = Username })); } return(Page()); }
static void Main(string[] args) { Blogs bloginstance = new Blogs(1231654); bloginstance.blogger = "ajay"; // internal bloginstance.blogpost = "some thing about C sharp"; // public bloginstance.rating = 5; // public }
public static Blogs CreateBlogs(int ID, string name, string owner) { Blogs blogs = new Blogs(); blogs.Id = ID; blogs.Name = name; blogs.Owner = owner; return blogs; }
private bool IsRead(Blogs.ModelDB.Blogs blogobj, string md5) { if (blogobj.BlogReadInfo.Where(t => t.MD5 == md5 && t.LastTime.AddHours(24) > DateTime.Now).Count() > 0) return true; else { //BLL. blogobj.BlogReadInfo.Add(new Blogs.ModelDB.BlogReadInfo() { MD5 = md5, IsDel = false, BlogsId = blogobj.Id, CreateTime = DateTime.Now, UpTime = DateTime.Now, LastTime = DateTime.Now }); return false; } }
public CreateBlogViewModel(Blogs blog, List<Category> categories) { Blog = blog; Categories = new SelectList(categories.ToList(), "ID", "CategoryName"); }
public void AddToBlogs(Blogs blogs) { base.AddObject("Blogs", blogs); }
public ViewBlogViewModel(Blogs blog, List<Comments> comments, string categoryName) { this.Blog = blog; Comments = comments; CategoryName = categoryName; }
public bool Add(Blogs blog) { BlogService._blgContext.Blogs.Add(blog); BlogService._blgContext.SaveChanges(); return true; }
/// <summary> /// Create a new Blogs object. /// </summary> /// <param name="blogID">Initial value of BlogID.</param> /// <param name="blogDescription">Initial value of BlogDescription.</param> /// <param name="blog">Initial value of Blog.</param> public static Blogs CreateBlogs(long blogID, string blogDescription, string blog) { Blogs blogs = new Blogs(); blogs.BlogID = blogID; blogs.BlogDescription = blogDescription; blogs.Blog = blog; return blogs; }
public User(object mixWith) : base(mixWith) { blogs = new Blogs(); }
public Comment(object dto) : base(dto) { Blogs = new Blogs(); }
public void Update(Blogs blog) { visuals.Output("Blog from " + blog.Name + " on " + blog.Topic); }