Пример #1
0
        public ActionResult ImageUploader(TestUploadImage model, HttpPostedFileBase image1)
        {
            var db = new Edlooker_DevEntities1();

            if (image1 != null)
            {
                String ImageFileName = Path.GetFileName(image1.FileName);
                String FolderPath    = Path.Combine(Server.MapPath("~/Images"), ImageFileName);
                image1.SaveAs(FolderPath);
                model.Name      = image1.FileName;
                model.Size      = image1.ContentLength;
                model.ImageData = new byte[image1.ContentLength];
                image1.InputStream.Read(model.ImageData, 0, image1.ContentLength);
            }
            db.TestUploadImages.Add(model);
            db.SaveChanges();
            return(View());
        }
        public String InsertNewsbg(String Headings, String URL, String Description, String Tags, String FrmSrc, String ImgSrc)
        {
            using (var context = new Edlooker_DevEntities1())
            {
                try
                {
                    PNEW _NewNews = new PNEW();
                    _NewNews.Heading     = Headings;
                    _NewNews.URL         = URL;
                    _NewNews.Description = Description;
                    _NewNews.Tags        = Tags;
                    _NewNews.FromSource  = FrmSrc;
                    _NewNews.ImageSrc    = ImgSrc;
                    _NewNews.UpdatedDate = DateTime.Now;
                    _NewNews.TotalView   = 0;
                    context.PNEWS.Add(_NewNews);
                    context.SaveChanges();
                    return("Success");
                }
                catch (DbEntityValidationException e)
                {
                    //Create empty list to capture Validation error(s)
                    var outputLines = new List <string>();

                    foreach (var eve in e.EntityValidationErrors)
                    {
                        outputLines.Add(
                            $"{DateTime.Now}: Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:");
                        outputLines.AddRange(eve.ValidationErrors.Select(ve =>
                                                                         $"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""));
                    }
                    //Write to external file
                    string RE = outputLines.ToString();
                    return("Failed");
                }
            }
        }
 public bool Insertblogbg(String Headings, String URL, String Description, String Tags, String FrmSrc, String ImgSrc)
 {
     using (var context = new Edlooker_DevEntities1())
     {
         try
         {
             PBLOG _NewBlog = new PBLOG();
             _NewBlog.Heading     = Headings;
             _NewBlog.URL         = URL;
             _NewBlog.Description = Description;
             _NewBlog.Tags        = Tags;
             _NewBlog.FromSource  = FrmSrc;
             _NewBlog.ImageSource = ImgSrc;
             _NewBlog.UpdatedDate = DateTime.Now;
             context.PBLOGs.Add(_NewBlog);
             context.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }