コード例 #1
0
        public IActionResult Create([FromForm] string username, [FromForm] string password, [FromForm] string passwordverify)
        {
            if (username == null || password == null || passwordverify == null)
            {
                ViewData["Message"] = "Error all items need to be created";
                return(View());
            }
            else if (!password.Equals(passwordverify))
            {
                ViewData["Message"] = $"Passwords dont match {password} {passwordverify}";
                return(View());
            }

            PasswordHash passwordHash = new PasswordHash(password);

            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();

                User user = new User();
                user.Username = username;
                user.Password = passwordHash.ToArray();
                context.Users.Add(user);
                context.SaveChanges();
            }
            ViewData["Message"] = "Account created";
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <IActionResult> Index([FromForm] string name, [FromForm] IFormFile file)
        {
            int userId = 0;

            if (!file.ContentType.Equals("video/mp4"))
            {
                ViewData["Message"] = "File not correct type mp4 files only";
                return(View());
            }

            userId = int.Parse(this.User.Claims.FirstOrDefault().Value);

            BucketAccess bucket = new BucketAccess();
            string       url    = await bucket.UpdateFile(file.FileName, file.ContentType, file.OpenReadStream());

            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();
                User  user  = context.Users.Find(userId);               //
                Video video = new Video
                {
                    Name      = name,
                    bucketurl = url,
                    User      = user,
                };
                context.Videos.Add(video);
                context.SaveChanges();
            }

            ViewData["Message"] = "File successfully uploaded upload another?";
            return(View());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: aagavin/dotNetflix
        public static void Main(string[] args)
        {
            BucketAccess bucket = new BucketAccess();

            using (var context = new DbSqlContext()){
                context.Database.EnsureCreated();
            }
            BuildWebHost(args).Run();
        }
コード例 #4
0
ファイル: VideoController.cs プロジェクト: aagavin/dotNetflix
        /// <summary>
        /// Shows all the videos
        /// </summary>
        /// <returns>IActionResult</returns>
        public IActionResult Index()
        {
            using (var context = new DbSqlContext()){
                context.Database.EnsureCreated();
                ViewData["Videos"] = context.Videos.ToArray();
            }

            return(View());
        }
コード例 #5
0
        /// <summary>
        /// Home page of the application
        /// Shows the top viewed videos and
        /// the top commented video
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Index()
        {
            using (var context = new DbSqlContext()){
                await context.Database.EnsureCreatedAsync();

                ViewData["TopViewVideos"] = await context.Videos
                                            .Where(v => v.views > 50)
                                            .OrderBy(v => v.views)
                                            .Take(5)
                                            .ToListAsync();

                ViewData["topCommentVideo"] = await context.Videos
                                              .Where(v => v.Comments.Count > 1)
                                              .OrderBy(v => v.Comments.Count)
                                              .Take(5)
                                              .ToListAsync();
            }
            return(View());
        }
コード例 #6
0
        public IActionResult Index()
        {
            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();
                // get userid of logged in user
                int userid   = int.Parse(this.User.Claims.FirstOrDefault().Value);
                var comments = context.Comments.Where(c => c.User.Userid == userid).ToList();

                var videos = context.Videos
                             .Where(v => v.User.Userid == userid)
                             .Include(v => v.Comments)
                             .ToList();

                ViewData["Comments"] = comments;
                ViewData["Videos"]   = videos;
                return(View());
            }
        }
コード例 #7
0
        public async Task <IActionResult> Signin([FromForm] string username, [FromForm] string password, string returnUrl = null)
        {
            Console.WriteLine($"{username} {password}");

            if (username == null || password == null)
            {
                return(View());
            }

            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();

                User user = context.Users.Where(u => u.Username == username).FirstOrDefault();

                PasswordHash passwordHash = new PasswordHash(user.Password);

                if (!passwordHash.Verify(password))
                {
                    return(Redirect("/account/signin"));
                }

                var claims = new List <Claim> {
                    new Claim("id", user.Userid.ToString()),
                    new Claim("name", user.Username),
                    new Claim("role", "user")
                };

                var ci = new ClaimsIdentity(claims, "password", "name", "role");
                var p  = new ClaimsPrincipal(ci);

                await HttpContext.SignInAsync(p);
            }

            if (Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(Redirect("/"));
            }
        }
コード例 #8
0
        public IActionResult UpdateComment([FromForm] string userComment, [FromForm] int commentId, [FromForm] int?delete)
        {
            using (var context = new DbSqlContext()){
                context.Database.EnsureCreated();

                var comment = context.Comments.Find(commentId);

                if (delete != null)
                {
                    context.Remove(comment);
                }
                else
                {
                    comment.UserComment = userComment;
                }
                context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
コード例 #9
0
ファイル: SqlLite.cs プロジェクト: egbertn/Peshitta
        public async Task RemoveDuplicates()
        {
            var optionsLite = new DbContextOptionsBuilder <DbSqlContext>().UseSqlite(dbSqliteContext.Database.GetDbConnection().ConnectionString).Options;
            var newCn       = new DbSqlContext(optionsLite);
            var cmd         = dbSqliteContext.Database.GetDbConnection().CreateCommand();
            await cmd.Connection.OpenAsync();

            await newCn.Words.FirstOrDefaultAsync();

            var cmdWithHash = dbSqliteContext.Database.GetDbConnection().CreateCommand();

            cmd.CommandText         = "SELECT DISTINCT wordid FROM textwords WHERE wordid in (select id from words where hash IS NULL AND isnumber = 0)";
            cmdWithHash.CommandText = "SELECT id FROM words WHERE word=@w AND NOT hash IS NULL";
            var par = cmdWithHash.CreateParameter();

            par.ParameterName = "@w";
            par.DbType        = System.Data.DbType.String;
            cmdWithHash.Parameters.Add(par);
            var data = await cmd.ExecuteReaderAsync();

            while (await data.ReadAsync())
            {
                var d          = data.GetInt32(0);
                var wordRecord = await dbSqliteContext.Words.FindAsync(d);

                par.Value = wordRecord.word;
                try
                {
                    var wid = await cmdWithHash.ExecuteScalarAsync();

                    await dbSqliteContext.Database.ExecuteSqlRawAsync($"UPDATE textwords SET wordid={wid} WHERE wordid={d}");

                    dbSqliteContext.Database.ExecuteSqlRaw($"UPDATE textwordshistory SET wordid={wid} WHERE wordid={d}");
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                }
            }
            //TODO fix words to be lang 19
        }
コード例 #10
0
ファイル: VideoController.cs プロジェクト: aagavin/dotNetflix
        public IActionResult AddComment([FromForm] string comment, [FromForm] int videoId)
        {
            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();

                var user  = context.Users.Find(int.Parse(this.User.Claims.FirstOrDefault().Value));
                var video = context.Videos.Find(videoId);

                Comment newComment = new Comment {
                    User        = user,
                    UserComment = comment,
                    Video       = video,
                };

                context.Add(newComment);
                context.SaveChanges();
            }

            return(RedirectToAction("Id", new { id = videoId }));
        }
コード例 #11
0
        public IActionResult UpdateVideo([FromForm] int id, [FromForm] string name, [FromForm] int?delete)
        {
            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();
                var video = context.Videos
                            .Include(v => v.Comments)
                            .Single(v => v.Videoid == id);

                if (delete != null)
                {
                    context.Remove(video);
                }
                else
                {
                    video.Name = name;
                }
                context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
コード例 #12
0
ファイル: VideoController.cs プロジェクト: aagavin/dotNetflix
        /// <summary>
        /// Gets a video by id and
        /// updates the view count
        /// </summary>
        /// <param name="id"></param>
        /// <returns>IActionResult</returns>
        public IActionResult Id([FromRoute] int id)
        {
            using (var context = new DbSqlContext())
            {
                context.Database.EnsureCreated();
                var video = context.Videos
                            .Include(v => v.User)
                            .Include(v => v.Comments)
                            .ThenInclude(c => c.User)
                            .Single(v => v.Videoid == id);

                video.views++;

                ViewData["Id"]        = video.Videoid;
                ViewData["Name"]      = video.Name;
                ViewData["User"]      = video.User.Username;
                ViewData["Views"]     = video.views;
                ViewData["bucketurl"] = video.bucketurl;
                ViewData["Comments"]  = video.Comments;
                context.SaveChanges();
            }
            return(View());
        }
コード例 #13
0
ファイル: BijbelRepository.cs プロジェクト: egbertn/Peshitta
 public BijbelRepository(DbSqlContext context)
 {
     _context = context;
 }
コード例 #14
0
ファイル: SqlLite.cs プロジェクト: egbertn/Peshitta
        public void Init()
        {
            var connectionString     = ConfigurationManager.ConnectionStrings["bijbel2"].ConnectionString;
            var connectionStringLite = ConfigurationManager.ConnectionStrings["bijbel"].ConnectionString;
            //var _options = new DbContextOptionsBuilder<DbSqlContext>()
            //    .UseSqlite(connectionString)
            //    .Options;
            var _options = new DbContextOptionsBuilder <DbSqlContext>()
                           .UseSqlServer(connectionString)
                           .Options;

            dbSqlContext = new DbSqlContext(_options);
            var optionsLite = new DbContextOptionsBuilder <DbSqlContext>().UseSqlite(connectionStringLite).Options;

            dbSqliteContext = new DbSqlContext(optionsLite);

            _repo = new BijbelRepository(dbSqliteContext);
            try
            {
                //dbSqliteContext.Database.EnsureDeleted();
                //dbSqliteContext.Database.EnsureCreated();
            }
            catch (InvalidOperationException inv)
            {
                throw inv;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            try
            {
                dbSqlContext.Database.EnsureDeleted();
                dbSqlContext.Database.EnsureCreated();
            }
            catch (InvalidOperationException inv)
            {
                throw inv;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Peshitta.Infrastructure.Models.Book, Peshitta.Infrastructure.Sqlite.Model.Book>()
                .ForMember(m => m.abbrevation, opt => opt.MapFrom(m => m.abbreviation ?? m.Title.Substring(0, 2)));
                cfg.CreateMap <Peshitta.Infrastructure.Models.BookEdition, Peshitta.Infrastructure.Sqlite.Model.bookedition>().
                ForMember(m => m.keywords, opt => opt.MapFrom(map => map.keywords != null ? string.Join(",", map.keywords): null));
                cfg.CreateMap <Peshitta.Infrastructure.Models.Text, Peshitta.Infrastructure.Sqlite.Model.Text>();
                cfg.CreateMap <Peshitta.Infrastructure.Models.words, Peshitta.Infrastructure.Sqlite.Model.words>();
                cfg.CreateMap <Peshitta.Infrastructure.Models.BookChapter, Peshitta.Infrastructure.Sqlite.Model.BookChapter>();
                cfg.CreateMap <Peshitta.Infrastructure.Models.BookChapterAlinea, Peshitta.Infrastructure.Sqlite.Model.BookChapterAlinea>();
                cfg.CreateMap <Peshitta.Infrastructure.Models.TextWords, Peshitta.Infrastructure.Sqlite.Model.TextWords>();
                cfg.CreateMap <Peshitta.Infrastructure.Models.TextWordsHistory, Peshitta.Infrastructure.Sqlite.Model.TextWordsHistory>();
            });

            mapper = mapConfig.CreateMapper();
            var start = Environment.TickCount;

            kitabDb = KitabDB.LoadFromDiskAsync(baseF, false).Result;
            Debug.WriteLine("Loading KitabDB took {0} ms", Environment.TickCount - start);

            start   = Environment.TickCount;
            kitabDb = KitabDB.LoadFromDiskAsync(baseF, false).Result;
            Debug.WriteLine("Loading KitabDB including the cache took {0} ms", Environment.TickCount - start);
        }