예제 #1
0
        public ActionResult Fractal1()
        {
            string email = User.Identity.Name;

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            FractalGenerator.GenereateFractal1(email).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] bitmapData = ms.ToArray();
            return(File(bitmapData, "image/jpeg"));
        }
예제 #2
0
        public ActionResult SaveEvent(EventCategoryViewModel vm, HttpPostedFileBase file, string newItem = null)
        {
            if (SpamDetector.IsContentSpam(vm.GamingEvent.Title))
            {
                return(RedirectToAction("Index", "Post"));
            }
            //Verify whether user has neccessary data
            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }


            int idd = vm.GamingEvent.GamingEventId;

            var gameEvent = vm.GamingEvent;

            if (file != null && file.ContentLength > 0)
            {
                if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png")
                {
                    var sourceImage = Image.FromStream(file.InputStream);

                    sourceImage = ResizeImage(sourceImage, 500, 500);

                    //Generowanie plik
                    var fileExt  = Path.GetExtension(file.FileName);
                    var filename = Guid.NewGuid() + fileExt; // Unikalny identyfikator + rozszerzenie

                    //W jakim folderze ma byc umiesczony dany plik oraz jego nazwa! Oraz zapis
                    var path = Path.Combine(Server.MapPath(AppConfig.ImagesGamingEventFolder), filename);
                    //file.SaveAs(path);
                    sourceImage.Save(path);
                    gameEvent.MainPicture = filename;
                }
            }
            else if (file == null && newItem != null && newItem != String.Empty)
            {
                var fractImg = FractalGenerator.GenereateFractal1(user.Email);
                var filename = Guid.NewGuid() + ".jpg";
                var path     = Path.Combine(Server.MapPath(AppConfig.ImagesGamingEventFolder), filename);
                fractImg.Save(path);
                gameEvent.MainPicture = filename;
            }

            gameEvent.UserId    = user.Id;
            gameEvent.Publisher = user;

            context.GamingEvents.AddOrUpdate(gameEvent);
            context.SaveChanges();

            return(RedirectToAction("Events", "Manage"));
        }
예제 #3
0
        public ActionResult SaveGame(GameCategoryViewModel vm, HttpPostedFileBase file, string newItem = null)
        {
            //Verify whether user has neccessary data
            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();

            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }
            if (user.UserInformation == null)
            {
                RedirectToAction("Index", new { errorMessage = "Proszę wypełnić swoje dane przed dodaniem gry" });
            }

            int idd = vm.Game.GameId;

            var game = vm.Game;

            if (file != null && file.ContentLength > 0)
            {
                if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png")
                {
                    var sourceImage = Image.FromStream(file.InputStream);

                    sourceImage = ResizeImage(sourceImage, 500, 500);

                    //Generowanie plik
                    var fileExt  = Path.GetExtension(file.FileName);
                    var filename = Guid.NewGuid() + fileExt; // Unikalny identyfikator + rozszerzenie

                    //W jakim folderze ma byc umiesczony dany plik oraz jego nazwa! Oraz zapis
                    var path = Path.Combine(Server.MapPath(AppConfig.ImagesGameFolder), filename);
                    //file.SaveAs(path);
                    sourceImage.Save(path);
                    game.MainPicture = filename;
                }
            }
            else if (file == null && newItem != null && newItem != String.Empty)
            {
                var fractImg = FractalGenerator.GenereateFractal1(user.Email);
                var filename = Guid.NewGuid() + ".jpg";
                var path     = Path.Combine(Server.MapPath(AppConfig.ImagesGameFolder), filename);
                fractImg.Save(path);
                game.MainPicture = filename;
            }

            game.GamesForExchange = System.Text.RegularExpressions.Regex.Replace(game.GamesForExchange, "[^0-9a-zA-ZżźćńółęąśŻŹĆĄŚĘŁÓŃ ]+", "|");
            game.UserId           = user.Id;


            context.Games.AddOrUpdate(game);
            context.SaveChanges();

            return(RedirectToAction("Games", "Manage"));
        }
예제 #4
0
        public ActionResult SavePost(PostCategoryViewModel vm, HttpPostedFileBase file, string newItem = null)
        {
            #region Spam Detextion
            if (SpamDetector.IsContentSpam(vm.Post.Title))
            {
                return(RedirectToAction("Index", "Post"));
            }
            #endregion

            #region GetUserAndSaveUserImage
            //Verify whether user has neccessary data
            ApplicationUser user = null;
            string          id   = User.Identity.GetUserId();
            if (id != string.Empty && id != null)
            {
                user = context.Users.Where(a => a.Id == id).First();
            }


            int idd = vm.Post.PostId;

            var post = vm.Post;
            if (file != null && file.ContentLength > 0)
            {
                if (Path.GetExtension(file.FileName).ToLower() == ".jpg" || Path.GetExtension(file.FileName).ToLower() == ".png")
                {
                    var sourceImage = Image.FromStream(file.InputStream);

                    sourceImage = ResizeImage(sourceImage, 500, 500);

                    //Generowanie plik
                    var fileExt  = Path.GetExtension(file.FileName);
                    var filename = Guid.NewGuid() + fileExt; // Unikalny identyfikator + rozszerzenie

                    //W jakim folderze ma byc umiesczony dany plik oraz jego nazwa! Oraz zapis
                    var path = Path.Combine(Server.MapPath(AppConfig.ImagesPostFolder), filename);
                    //file.SaveAs(path);
                    sourceImage.Save(path);
                    post.MainPicture = filename;
                }
            }
            else if (file == null && newItem != null && newItem != String.Empty)
            {
                var fractImg = FractalGenerator.GenereateFractal1(user.Email);
                var filename = Guid.NewGuid() + ".jpg";
                var path     = Path.Combine(Server.MapPath(AppConfig.ImagesPostFolder), filename);
                fractImg.Save(path);
                post.MainPicture = filename;
            }

            #endregion

            #region Sentimental Analisys
            var sentimentalInt = new SentimentalInterpreter();
            var isContentHappy = sentimentalInt.IsHappy(post.Title);
            if (isContentHappy)
            {
                post.IsHappy = true;
            }
            #endregion

            post.DateOfInsert = DateTime.Now;
            post.UserId       = user.Id;
            post.User         = user;

            if (user.Posts.Where(a => a.PostId == post.PostId).Count() == 0)
            {
                user.Posts.Add(post);
            }

            context.Posts.AddOrUpdate(post);
            context.SaveChanges();



            //InsertOrUpdate(post);

            return(RedirectToAction("Post", "Manage"));
        }