Exemple #1
0
        public ActionResult DeleteImage(int ImageID)
        {
            if (ImageID == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            NewsPicture NewsPic = db.NewsPicture.Where(p => p.ID == ImageID).FirstOrDefault();

            if (NewsPic == null)
            {
                return(HttpNotFound());
            }

            db.NewsPicture.Remove(NewsPic);
            db.SaveChanges();

            string fullPath = Request.MapPath("~/Images/NewsImages/" + NewsPic.PicURL);

            if (System.IO.File.Exists(fullPath))
            {
                System.IO.File.Delete(fullPath);
            }

            return(RedirectToAction("DisplayImages", new { id = NewsPic.NewsID }));
        }
Exemple #2
0
        /// <summary>
        /// Updates a news picture
        /// </summary>
        /// <param name="newsPicture">News picture</param>
        public virtual void UpdateNewsPicture(NewsPicture newsPicture)
        {
            if (newsPicture == null)
            {
                throw new ArgumentNullException("newsPicture");
            }

            _newsPictureRepository.Update(newsPicture);

            //event notification
            _eventPublisher.EntityUpdated(newsPicture);
        }
Exemple #3
0
        public static NewsPicture CreatePicture(News news, string url)
        {
            NewsPicture result = new NewsPicture();

            result.Guid      = Guid.NewGuid();
            result.ImageLink = url;
            result.News      = news;
            result.SortOrder = news.NewsPictures.Count;
            news.NewsPictures.Add(result);

            return(result);
        }
        public void DeleteIMG(string picture)
        {
            NewsPicture vgp = new NewsPicture();

            if (picture == null)
            {
                return;
            }
            var    fo  = picture.Substring(0, 3);
            string dir = Server.MapPath("~/UploadImg/" + fo + "/" + picture);

            System.IO.File.Delete(dir);
        }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                await _friendService.FetchFriendList();

                var newsLoader = new NewsPictureLoader();
                _currentNews = await newsLoader.GetNewsDescription();

                SetNewsPictureSource(_currentNews.ImageSource);
            }
            catch
            {
                _currentNews = NewsPicture.Default();
            }
        }
        public void CreateNewsPicture()
        {
            using (var context = new YoumotoDbContext(Effort.DbConnectionFactory.CreateTransient()))
            {
                String      url         = "https://www.youmoto.com/test.jpg";
                News        news        = NewsPersister.Create("MyTitle");
                NewsPicture newsPicture = NewsPersister.CreatePicture(news, url);

                context.News.Add(news);
                context.SaveChanges();

                Assert.AreEqual(1, context.News.Count());
                Assert.AreEqual(1, context.NewsPictures.Count());
                Assert.AreEqual(1, context.News.First().NewsPictures.Count());
                Assert.AreEqual(url, context.News.First().NewsPictures.First().ImageLink);
            }
        }
Exemple #7
0
        public ActionResult DisplayImages(NewsPictureViewModel NewsVM, HttpPostedFileBase ImageUpload)
        {
            if (ImageUpload != null)
            {
                if (ImageUpload.ContentType == "image/jpg" || ImageUpload.ContentType == "image/png" || ImageUpload.ContentType == "image/jpeg")
                {
                    ImageUpload.SaveAs(Server.MapPath("/") + "/Images/NewsImages/" + ImageUpload.FileName);

                    NewsPicture NewsPic = new NewsPicture();
                    NewsPic.NewsID = NewsVM.ID;
                    NewsPic.PicURL = ImageUpload.FileName;
                    db.NewsPicture.Add(NewsPic);
                    db.SaveChanges();
                    return(RedirectToAction("DisplayImages", new { id = NewsVM.ID }));
                }
            }

            return(RedirectToAction("DisplayImages", new { id = NewsVM.ID }));
        }
        public void SaveImg(NewsPicture newPicture)
        {
            var    t          = newPicture.cfile ?? "";
            var    file       = t.Replace("data:image/png;base64,", "");
            var    photoBytes = Convert.FromBase64String(file);
            string format     = "jpg";

            if (newPicture.isactive == 1)
            {
                newPicture.isactive = 1;
            }
            else
            {
                newPicture.isactive = 2;
            }
            var picture = new NewsPicture
            {
                tblPicture = new BDSPicture {
                    advert_id = newPicture.idProducts, Active = 1, angleType = 0, cms_sql_id = 0, converted = DateTime.Now, tocheck = true, type_id = 1, title = newPicture.nameImg, position = newPicture.isactive
                }
            };

            if (newPicture.idpicture == 0)
            {
                var settings = new ResizeSettings();
                settings.Scale  = ScaleMode.DownscaleOnly;
                settings.Format = format;

                //string uploadFolder = picture.DirectoryPhysical;

                string path = Server.MapPath("~/UploadImg/") + DateTime.Now.Day + DateTime.Now.Month + "/";
                // check for directory
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                // filename with placeholder for size
                if (picture.GetConvertedFileName() == null || string.IsNullOrWhiteSpace(picture.GetConvertedFileName()))
                {
                    picture.SetFileName(DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + "_" + picture.CreateFilename() + "_{0}." + format);
                }

                if (picture.GetFilePathPhysical(NewsPicture.PictureSize.Large) != null)
                {
                    string dest = path + picture.FileName(NewsPicture.PictureSize.Large);
                    settings.MaxWidth  = 720;
                    settings.MaxHeight = 405;
                    if (picture.WaterMarkLarge == NewsPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(NewsPicture.PictureSize.Large);
                    }
                }

                if (picture.GetFilePathPhysical(NewsPicture.PictureSize.Medium) != null)
                {
                    string dest = path + picture.FileName(NewsPicture.PictureSize.Medium);
                    settings.MaxWidth  = 320;
                    settings.MaxHeight = 180;
                    if (picture.WaterMarkLarge == NewsPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(NewsPicture.PictureSize.Medium);
                    }
                }
                if (picture.GetFilePathPhysical(NewsPicture.PictureSize.Tiny) != null)
                {
                    string dest = path + picture.FileName(NewsPicture.PictureSize.Tiny);
                    settings.MaxWidth  = 220;
                    settings.MaxHeight = 123;
                    if (picture.WaterMarkLarge == NewsPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(NewsPicture.PictureSize.Tiny);
                    }
                }

                if (picture.GetFilePathPhysical(NewsPicture.PictureSize.Small) != null)
                {
                    string dest = path + picture.FileName(NewsPicture.PictureSize.Small);
                    settings.MaxWidth  = 120;
                    settings.MaxHeight = 67;
                    if (picture.WaterMarkLarge == NewsPicture.WatermarkType.None)
                    {
                        ImageBuilder.Current.Build(photoBytes, dest, settings, false, false);
                    }
                    // save biggest version as original
                    if (string.IsNullOrWhiteSpace(picture.tblPicture.originalFilepath))
                    {
                        picture.tblPicture.originalFilepath = picture.GetFilePath(NewsPicture.PictureSize.Small);
                    }
                }
                db.BDSPictures.Add(picture.tblPicture);
                db.SaveChanges();
            }
            if (newPicture.idpicture > 0)
            {
                BDSPicture tblpict = db.BDSPictures.Find(newPicture.idpicture);
                tblpict.title           = newPicture.nameImg;
                tblpict.position        = newPicture.isactive;
                db.Entry(tblpict).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
 public void UpdateNewsPicture(NewsPicture newsPicture)
 {
     _newsPictureRepository.Update(newsPicture);
 }
Exemple #10
0
 public void InsertNewsPicture(NewsPicture newsPicture)
 {
     _newsPictureRepository.Insert(newsPicture);
 }
 public static NewsPicture ToEntity(this NewsPictureModel model, NewsPicture destination)
 {
     return(model.MapTo(destination));
 }
 public static NewsPictureModel ToModel(this NewsPicture entity)
 {
     return(entity.MapTo <NewsPicture, NewsPictureModel>());
 }