コード例 #1
0
        public ActionResult Edit(NewsItem newsItem, HttpPostedFileBase file)
        {
            var filePath = HttpContext.Server.MapPath("../MyFiles");

            var fullPath = Path.Combine(filePath, "news.jpg");

            if(file!=null)
                ImageProcessor.ResizeAndSaveImage(400,400, fullPath, file.InputStream);
            else
            {
                //delete news image
                if(System.IO.File.Exists(fullPath))
                    System.IO.File.Delete(fullPath);
            }

            using (var artGalleryDbContext = new ArtGalleryDBContext())
            {
                var currentNews = artGalleryDbContext.NewsItem.FirstOrDefault();
                if (currentNews != null)
                {
                    currentNews.Body = newsItem.Body;
                    currentNews.Subject = newsItem.Subject;
                }
                else
                    artGalleryDbContext.NewsItem.Add(newsItem);

                artGalleryDbContext.SaveChanges();
            }

            return RedirectToAction("Index");
            //news.Image = new byte[file.InputStream.Length];
            //file.InputStream.Rea
        }
コード例 #2
0
 public ActionResult Index()
 {
     NewsItem news    = null;
     using(var artGalleryDbContext = new ArtGalleryDBContext())
     {
         news = artGalleryDbContext.NewsItem.FirstOrDefault();
     }
     return View(news);
 }
コード例 #3
0
ファイル: Permissions.cs プロジェクト: richinoz/Art1stLeeds
        public static bool HasPermission(IPrincipal user, IPermissions permissions)
        {
            ArtGalleryDBContext db = new ArtGalleryDBContext();
            IUserDal userDal = new UserDal(db);

            var currentUser = GetCurrentUser(userDal, user);

            if (currentUser != null && currentUser.Permissions!=null)
            {

                if (currentUser.Permissions.Contains(permissions.Values))
                    return true;
            }

            return false;
        }
コード例 #4
0
ファイル: PictureCache.cs プロジェクト: richinoz/Art1stLeeds
        public static Bitmap GetImage(string path, long screenWidth, long screenHeight, long picId)
        {
            Bitmap bitmap = null;
            byte[] pBuffer = null;

            string fullImagePath = path + ".jpg";
            string smallImagePath = path + "_s.jpg";
            //only retrieve from db if not on disk
            if (File.Exists(fullImagePath))
            {

                if (File.Exists(smallImagePath))
                {
                    var img = System.Drawing.Image.FromFile(smallImagePath);
                    bitmap = new Bitmap(img);
                }
                else
                {
                    pBuffer = ImageProcessor.CreateThumbnail(fullImagePath, 150, 150, "jpg");
                    ImageProcessor.ResizeAndSaveImage(150, 150, smallImagePath, pBuffer);
                }

            }
            else
            {
                using (ArtGalleryDBContext db = new ArtGalleryDBContext())
                {
                    var pic = db.Pictures.Find(picId);
                    ImageProcessor.ResizeAndSaveImage(screenWidth, screenHeight, fullImagePath, pic.ImageT);

                    pBuffer = ImageProcessor.CreateThumbnail(fullImagePath, 150, 150, ".jpg");
                    ImageProcessor.ResizeAndSaveImage(150, 150, smallImagePath, pBuffer);
                }
            }

            // Convert Byte[] to Bitmap
            if (bitmap == null)
                bitmap = ConvertToBitmap(pBuffer);

            return bitmap;
        }
コード例 #5
0
ファイル: PictureCache.cs プロジェクト: richinoz/Art1stLeeds
        public static void Refresh(string filePath, bool deleteFiles = false)
        {
            lock (_lockObj)
            {
                using (var db = new ArtGalleryDBContext())
                {
                    var pics = PictureEditorController.GetImagesFromDbMin("");

                    IPictureDal pictureDal = new PictureDal(db);

                    //delete all disk files
                    if (filePath != null && deleteFiles)
                    {

                        var files = Directory.GetFiles(filePath);
                        foreach (var file in files)
                        {
                            File.Delete(file);
                        }

                        //re-write images
                        foreach (var pic in pics)
                        {
                            try
                            {
                                string fullImagePath = filePath + pic.ID + ".jpg";
                                string smallImagePath = filePath + pic.ID + "_s.jpg";

                                var picWithData = pictureDal.Enitities.Find(pic.ID);
                                ImageProcessor.ResizeAndSaveImage(1280, 720, fullImagePath, picWithData.ImageT);

                                var pBuffer = ImageProcessor.CreateThumbnail(fullImagePath, 150, 150, ".jpg");
                                ImageProcessor.ResizeAndSaveImage(150, 150, smallImagePath, pBuffer);
                            }
                            catch (Exception ex)
                            {
                                Logger.Error("in Refresh cache", ex);
                            }

                        }

                    }
                    else
                    {
                        try
                        {

                            //re-write images
                            foreach (var pic in pics)
                            {

                                string fullImagePath = filePath + pic.ID + ".jpg";
                                string smallImagePath = filePath + pic.ID + "_s.jpg";

                                if (!File.Exists(fullImagePath))
                                {
                                    var picWithData = pictureDal.Enitities.Find(pic.ID);
                                    ImageProcessor.ResizeAndSaveImage(1280, 720, fullImagePath, picWithData.ImageT);

                                    var pBuffer = ImageProcessor.CreateThumbnail(fullImagePath, 150, 150, ".jpg");
                                    ImageProcessor.ResizeAndSaveImage(150, 150, smallImagePath, pBuffer);
                                }

                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("in Refresh cache", ex);
                        }
                    }
                }

            }
        }
コード例 #6
0
        public ActionResult SendEmailByName(string artistName)
        {
            var db = new ArtGalleryDBContext();
            var artist = Helpers.Helpers.GetUserForName(artistName,db);

            EMailView eMailView = new EMailView() { LogOnModel = artist };
            ViewBag.Menu = "_ArtistHome";
            ViewBag.Model = artist;
            ViewBag.Title = artist.UserName;

            return View("SendEmail", eMailView);
        }
コード例 #7
0
        public ActionResult LandingPagePictureReplacer(int landPageItemId, int newPictureId)
        {
            using(var artDb = new ArtGalleryDBContext())
            {
                var landingPageDal = new LandingPageDal(artDb);
                var landingPageItem = landingPageDal.Enitities.FirstOrDefault(x => x.Id == landPageItemId);
                landingPageItem.PictureId = newPictureId;
                artDb.SaveChanges();

            }
            return RedirectToAction("Index", "Home");
        }
コード例 #8
0
ファイル: Upload.ashx.cs プロジェクト: richinoz/Art1stLeeds
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpPostedFile hpf = context.Request.Files["file"];
               // if (hpf.ContentLength > 0 && FileIsPicture(hpf))
                if (hpf.ContentLength > 0)
                {

                    int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0;
                    int totalChunks = context.Request["chunks"] != null ? int.Parse(context.Request["chunks"]) : 1;

                    string fileName = context.Request["name"] ?? string.Empty;

                    string filePath = context.Server.MapPath("MyFiles");

                    using (var fs = new FileStream(Path.Combine(filePath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
                    {
                        var buffer = new byte[hpf.InputStream.Length];
                        hpf.InputStream.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }

                    //only do this part when chunk complete
                    if (chunk == totalChunks-1)
                    {
                        byte[] bufferFinal = ImageProcessor.ImageAsByteArray(Path.Combine(filePath, fileName),
                                                                             System.Drawing.Imaging.ImageFormat.Jpeg);

                        using (ArtGalleryDBContext db = new ArtGalleryDBContext())
                        {
                            var currentUser =  UserDal.AllUsers.FirstOrDefault(x => x.UserName.ToLower() == context.User.Identity.Name.ToLower());
                            if (currentUser == null)
                            {
                                currentUser = new LogOnModel()
                                {
                                    UserId = 99999,
                                    UserName = context.User.Identity.Name
                                };
                                Logger.Info("user could not be found for upload", null);
                            }
                            var picture = new PictureItem
                                                      {
                                                          ImageT = bufferFinal,
                                                          Created = DateTime.Now,
                                                          Artist = currentUser.UserName,
                                                          UserId = currentUser.UserId
                                                      };

                            IPictureDal pictureDal = new PictureDal(db);
                            //saveto db
                            pictureDal.Enitities.Add(picture);
                            pictureDal.SaveChanges();

                        }

                    }

                }
                //save any old file to myFiles...
                //else
                //{
                //    string filePath = context.Server.MapPath("MyFiles") + "\\" +
                //                        System.IO.Path.GetFileName(hpf.FileName);

                //    hpf.SaveAs(filePath);
                //}

                context.Response.Write("1");
            }
            catch (Exception ex)
            {
                Logger.Error("In upload.ashx", ex);
            }
        }
コード例 #9
0
        private static IQueryable<PictureItem> GetImagesQuery(ArtGalleryDBContext db, string searchName)
        {
            var pictureDal = new PictureDal(db);

            bool except = false;

            if (String.IsNullOrEmpty(searchName))
                searchName = string.Empty;

            if (searchName.Length > 0 && searchName.Substring(0, 1) == "!")
            {
                searchName = searchName.Substring(1);
                except = true;
            }

            IQueryable<PictureItem> query = null;

            if (searchName.ToLower() == "anon")
                query =
                    pictureDal.Enitities.Where(x => (x.Artist == null) || (x.Artist.ToLower() == "anon"));

            if (searchName.ToLower() == "untitled")
                query =
                    pictureDal.Enitities.Where(x => (x.Title == null) || (x.Title.ToLower() == "untitled"));

            if (query == null)
                if (searchName != string.Empty)
                {
                    searchName = searchName.ToLower();

                    query = pictureDal.Enitities.Where(x => (x.Title != null && x.Title.ToLower().Contains(searchName)) ||
                                                   (x.Artist != null && x.Artist.ToLower().Contains(searchName)) ||
                                                   (x.Media != null && x.Media.ToLower().Contains(searchName)) ||
                                                   (x.Theme != null && x.Theme.ToLower().Contains(searchName)));
                }
                else
                    query = pictureDal.Enitities;

            if (except)
                return pictureDal.Enitities.Except(query);

            return query;
        }