public (JsonResult result, bool Succeeded) InsertBlogImage(Image image) { try { var entity = new BlogImage { BlogID = image.BlogID, ImageURL = image.ImageURL, StatusID = image.StatusID }; _context.BlogImages.Add(entity); if (_context.SaveChanges() == 1) { return(new JsonResult("Blog Image added successfully."), true); } else { return(new JsonResult("Enter the correct values."), false); } } catch (Exception ex) { return(new JsonResult("Some server error occured. Please try again!!"), false); } }
public async Task <IActionResult> Edit(int id, [Bind("BlogImageId,Image,Caption,BlogForeignKey")] BlogImage blogImage) { if (id != blogImage.BlogImageId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(blogImage); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogImageExists(blogImage.BlogImageId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BlogForeignKey"] = new SelectList(_context.Blogs, "BlogId", "BlogId", blogImage.BlogForeignKey); return(View(blogImage)); }
public void deleteBlogImage(int id) { BlogImage BlogImage = BlogImageRepository.GetById(id); BlogImageRepository.Delete(BlogImage); SaveChange(); }
static void Main(string[] args) { Blog blog = new Blog() { Url = "www.meublog.com" }; BlogImage blogImage = new BlogImage() { Image = "Imagem", Blog = blog }; CriarDatabase(); using (var db = new MyContext()) { try { db.Add(blogImage); db.SaveChanges(); Console.WriteLine("Objetos persistidos com sucesso!"); } catch (Exception ex) { Console.WriteLine("Erro ao persistir os objetos!"); Console.WriteLine(ex.Message); } } }
public void UpdateFag(BlogImage blogImageToUpdate, BlogImage model) { blogImageToUpdate.Status = model.Status; blogImageToUpdate.Image = model.Image; blogImageToUpdate.BlogId = model.BlogId; blogImageToUpdate.ModifiedDate = DateTime.Now; _context.SaveChanges(); }
public String SaveImage(BlogImage blogImage, String blogGuid) { using (OperationContextScope scope = new OperationContextScope(this.InnerChannel)) { AddGuidToMessageHeader(MinimaMessageHeaderType.BlogGuid, blogGuid); //+ return(base.Channel.SaveImage(blogImage, blogGuid)); } }
public IActionResult Update(int id, string caption) { BlogImage blogImageDb = _blogImageService.GetByIdDb(id); blogImageDb.Caption = caption; _blogImageService.Update(blogImageDb); _blogImageService.SaveChanges(); return(new OkObjectResult(id)); }
//- @SaveImage -// public static String SaveImage(BlogImage blogImage, String blogGuid) { using (ImageClient imageClient = new ImageClient(BlogSection.GetConfigSection().Service.Endpoint.Image)) { imageClient.ClientCredentials.UserName.UserName = BlogSection.GetConfigSection().Service.Authentication.DefaultUserName; imageClient.ClientCredentials.UserName.Password = BlogSection.GetConfigSection().Service.Authentication.DefaultPassword; //+ return(imageClient.SaveImage(blogImage, blogGuid)); } }
//- @SaveImage -// public static String SaveImage(BlogImage blogImage, String blogGuid) { using (ImageClient imageClient = new ImageClient(MinimaConfiguration.ActiveImageServiceEndpoint)) { imageClient.ClientCredentials.UserName.UserName = MinimaConfiguration.DefaultServiceUserName; imageClient.ClientCredentials.UserName.Password = MinimaConfiguration.DefaultServicePassword; //+ return(imageClient.SaveImage(blogImage, blogGuid)); } }
public IActionResult Delete(int id) { BlogImage img = _blogPhotosRepository.GetBlogPhotoById(id); if (img == null) { return(NotFound()); } _blogPhotosRepository.DeleteFag(img); return(RedirectToAction("index")); }
public void createBlogImage(BlogImage obj) { try { BlogImageRepository.Add(obj); SaveChange(); } catch { } }
public IActionResult Create(BlogImageViewModel img) { if (ModelState.IsValid) { BlogImage model = _mapper.Map <BlogImageViewModel, BlogImage>(img); model.CreatedBy = _admin.FullName; _blogPhotosRepository.CreateFag(model); return(RedirectToAction("index")); } return(View(img)); }
public async Task <IActionResult> Create([Bind("BlogImageId,Image,Caption,BlogForeignKey")] BlogImage blogImage) { if (ModelState.IsValid) { _context.Add(blogImage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BlogForeignKey"] = new SelectList(_context.Blogs, "BlogId", "BlogId", blogImage.BlogForeignKey); return(View(blogImage)); }
public IActionResult Edit(int id) { BlogImage img = _blogPhotosRepository.GetBlogPhotoById(id); if (img == null) { return(NotFound()); } var model = _mapper.Map <BlogImage, BlogImageViewModel>(img); ViewBag.Blogs = _blogRepository.GetBlogs(); return(View(model)); }
public IActionResult Edit(BlogImageViewModel img) { if (ModelState.IsValid) { BlogImage model = _mapper.Map <BlogImageViewModel, BlogImage>(img); model.ModifiedBy = _admin.FullName; BlogImage BlogImageToUpdate = _blogPhotosRepository.GetBlogPhotoById(img.Id); if (BlogImageToUpdate == null) { return(NotFound()); } _blogPhotosRepository.UpdateFag(BlogImageToUpdate, model); return(RedirectToAction("index")); } return(View(img)); }
public void DisableAllNavigationButton() { HomeImage.Background = null; HomeImage.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black); NotificationImage.Background = null; NotificationImage.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black); ProfileImage.Background = null; //ProfileImage.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black); TrendImage.Background = null; TrendImage.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black); BlogImage.Background = null; BlogImage.SetColorFilter(AppSettings.SetTabDarkTheme ? Color.White : Color.Black); }
public (JsonResult result, bool Succeeded) DeleteBlogImage(Guid id) { try { BlogImage blogImg = _context.BlogImages.Find(id); if (blogImg == null) { return(new JsonResult("Blog Description Not Found."), true); } blogImg.StatusID = false; _context.SaveChanges(); return(new JsonResult("Blog Description Deleted Successfully."), true); } catch (Exception ex) { return(new JsonResult("Some server error occured"), false); } }
private async Task <BlogImage> CreateImageAsync(Blog blog, byte[] picture, string picturePath, string pictureExtension) { var pictureData = this.blogImagesRepository.All().FirstOrDefault(i => i.BlogId == blog.Id); if (pictureData != null) { this.filesService.DeleteFile(picturePath, pictureData.Id, pictureData.Extension); } else { pictureData = new BlogImage(); } pictureData.Extension = pictureExtension; await this.filesService.SaveFileAsync(picture, picturePath, pictureData.Id, pictureExtension); return(pictureData); }
public async Task CreateAsync(CreateBlogInputModel input, string userId, string imagePath) { var blog = new Blog { Name = input.Name, SubName = input.SubName, Author = input.Author, Category = input.Category, Date = input.Date, Description = input.Description, AddedByUserId = userId, }; var allowedExtensions = new[] { "jpg", "png", "gif" }; Directory.CreateDirectory($"{imagePath}/blogs"); foreach (var image in input.BlogImages) { var extension = Path.GetExtension(image.FileName).TrimStart('.'); if (!allowedExtensions.Any(x => extension.EndsWith(x))) { throw new Exception($"Invalid Image Extension {extension}"); } var dbImage = new BlogImage { AddedByUserid = userId, Extension = extension, }; blog.BlogImages.Add(dbImage); var phycicalPath = $"{imagePath}/blogs/{dbImage.Id}.{extension}"; using Stream fileStream = new FileStream(phycicalPath, FileMode.Create); await image.CopyToAsync(fileStream); } await this.blogRepository.AddAsync(blog); await this.blogRepository.SaveChangesAsync(); }
public (JsonResult result, bool Succeeded) UpdateBlogImage(UpdatelogImage updatelogImage) { try { BlogImage blogImg = _context.BlogImages.FirstOrDefault(p => p.ImageURL == updatelogImage.ImageURL); _context.Entry(blogImg).CurrentValues.SetValues(updatelogImage); if (_context.SaveChanges() == 1) { return(new JsonResult("Blog Description updated successfully."), true); } else { return(new JsonResult("Enter the correct values."), false); } } catch (Exception ex) { return(new JsonResult("Some server error occured. Please try again!!"), false); } }
//+ //- @ProcessRequest -// public override void Process() { if (Themelia.Web.Http.GetUrlPart(Themelia.Position.Penultima) == "imagestore") { Byte[] buffer = HttpData.GetInputHttpByteArray(); String contentType = HttpData.GetHeaderItem(Info.ImageContentType); if (buffer != null && buffer.Length > 0 && !String.IsNullOrEmpty(contentType)) { String blogGuid = Themelia.Web.Http.GetUrlPart(Themelia.Position.Ultima); BlogImage blogImage = new BlogImage { ContentType = contentType, Data = buffer }; //+ try { Response.Write(ImageAgent.SaveImage(blogImage, blogGuid)); } catch { } } else { String blogImageGuid = Themelia.Web.Http.GetUrlPart(Themelia.Position.Ultima); if (!String.IsNullOrEmpty(blogImageGuid)) { BlogImage blogImage = ImageAgent.GetImage(blogImageGuid); if (blogImage.Data != null && blogImage.Data.Length > 0) { ContentType = blogImage.ContentType; Response.BinaryWrite(blogImage.Data); } } } } }
void save() { blog.PostTitle = txtTitle.Text; blog.IsNews = chkNews.Checked; blog.IsVisible = chkVis.Checked; for (int i = 0; i < rptSections.Items.Count; ++i) { TextBox tb = rptSections.Items[i].FindControl("txtContent") as TextBox; blog.Sections[i].Content = tb.Text; FileUpload fld = rptSections.Items[i].FindControl("flUpload") as FileUpload; if (fld.HasFile) { try { System.Drawing.Image img = System.Drawing.Image.FromStream(new MemoryStream(fld.FileBytes)); BlogImage image = new BlogImage(); image.ImageData = img; image.ImageName = fld.FileName; image.ImageDesc = ""; blog.Sections[i].BelowImage = image; } catch (Exception) { } } } }
public void editBlogImage(BlogImage obj) { BlogImageRepository.Update(obj); SaveChange(); }
public async Task <ActionResult> CreateNews([Bind(Include = "BlogId,Title,Post,UserId,DateCreated")] Blog blog, HttpPostedFileBase[] images, HttpPostedFileBase[] videos) { try { blog.UserId = User.Identity.GetUserId(); blog.DateCreated = DateTime.Now; blog.IsVisible = true; if (ModelState.IsValid) { _applicationDbContext.Blogs.Add(blog); await _applicationDbContext.SaveChangesAsync(); int newsId = 0; newsId = blog.BlogId; foreach (var img in images) { if (img != null) { string filename = DateTime.UtcNow.ToFileTimeUtc() + Path.GetExtension(img.FileName); img.SaveAs(Path.Combine(Server.MapPath("~/ImageUpload"), filename)); var blogModel = new BlogImage(); blogModel.ImageName = filename; blogModel.BlogId = newsId; blogModel.ImageCaption = "Article image"; blogModel.DateCreated = DateTime.UtcNow; _applicationDbContext.BlogImages.Add(blogModel); await _applicationDbContext.SaveChangesAsync(); } else { } } foreach (var vid in videos) { if (vid != null) { string filename = DateTime.UtcNow.ToFileTimeUtc() + Path.GetExtension(vid.FileName); vid.SaveAs(Path.Combine(Server.MapPath("~/VideoUpload"), filename)); var blogModel = new BlogVideo(); blogModel.VideoName = filename; blogModel.BlogId = newsId; blogModel.VideoCaption = "Article video"; blogModel.DateCreated = DateTime.UtcNow; _applicationDbContext.BlogVideos.Add(blogModel); await _applicationDbContext.SaveChangesAsync(); } else { } } //foreach (var doc in documents) //{ // if (doc != null) // { // string filename = DateTime.UtcNow.ToFileTimeUtc() + Path.GetExtension(doc.FileName); // doc.SaveAs(Path.Combine(Server.MapPath("~/Documents"), filename)); // var blogModel = new BlogImage(); // blogModel.ImageName = filename; // blogModel.BlogId = newsId; // blogModel.ImageCaption = "Article video"; // blogModel.DateCreated = DateTime.UtcNow; // _applicationDbContext.BlogImages.Add(blogModel); // await _applicationDbContext.SaveChangesAsync(); // } // else { } //} } } catch (Exception ex) { ViewBag.Message = "Could not publish article.Please try again later"; return(View(blog)); } ViewBag.Message = "You have successfully published article"; return(View()); }
public void CreateFag(BlogImage model) { model.AddedDate = DateTime.Now; _context.BlogImages.Add(model); _context.SaveChanges(); }
public void DeleteFag(BlogImage img) { _context.BlogImages.Remove(img); _context.SaveChanges(); }
public void Update(BlogImage blogImageDb) { _blogImageRepository.Update(blogImageDb); }