public HttpResponse Register(RegisterUserFormModel model)
        {
            var modelErrors = this.validator.ValidateUser(model);

            if (this.data.Users.Any(u => u.Username == model.Username))
            {
                modelErrors.Add($"User with '{model.Username}' username already exists.");
            }

            if (this.data.Users.Any(u => u.Email == model.Email))
            {
                modelErrors.Add($"User with '{model.Email}' e-mail already exists.");
            }

            if (modelErrors.Any())
            {
                return(Error(modelErrors));
            }

            var user = new User
            {
                Username = model.Username,
                Password = this.passwordHasher.HashPassword(model.Password),
                Email    = model.Email,
            };

            data.Users.Add(user);

            data.SaveChanges();

            return(Redirect("/Users/Login"));
        }
Exemplo n.º 2
0
        public void SeedGitUsers(int amount = 10000, bool tuned = false)
        {
            var data = Builder <GitHubResume> .CreateListOfSize(amount).All()
                       .With(c => c.PiplMatchedDate = Faker.Date.Past())
                       .With(c => c.Login           = Faker.User.Username())
                       .With(c => c.Location        = Faker.Address.SecondaryAddress())
                       .With(c => c.Name            = Faker.Name.FullName())
                       .With(c => c.Bio             = Faker.Lorem.Paragraph(10))
                       .With(c => c.Email           = Faker.User.Email())
                       .Build();

            using (var context = new GitDbContext())
            {
                if (tuned)
                {
                    context.BulkInsertAsync(data, amount).Wait();
                }
                else
                {
                    context.GitHubResumes.AddRange(data);
                    context.SaveChanges();
                }
                // EFBatchOperation.For(context, context.GitHubResumes).InsertAll(data);
                //context.AttachAndModify(data);
                //context.BulkInsert(data);
                //context.GitHubResumes.AddRange(data);
                // context.SaveChanges();
            }
        }
        public (ICollection <string>, bool) CreateRepository(RepositoryCreateFormModel model, string userId)
        {
            var information = this.validator.ValidateRepository(model);

            if (information.Count > 0)
            {
                return(information, false);
            }

            if (dbContext.Repositories.Any(x => x.Name == model.Name))
            {
                information.Add("There is already a repository with that name");
                return(information, false);
            }

            var repository = new Repository
            {
                IsPublic  = model.RepositoryType == "Public",
                Name      = model.Name,
                CreatedOn = System.DateTime.UtcNow,
                OwnerId   = userId,
            };

            dbContext.Repositories.Add(repository);
            dbContext.SaveChanges();

            information.Add(repository.Id);
            return(information, true);
        }
Exemplo n.º 4
0
        public ICollection <string> RegisterUser(RegisterUserFormModel model)
        {
            var modelErrors = this.validator.ValidateUser(model);

            if (this.dbcontext.Users.Any(u => u.Username == model.Username))
            {
                modelErrors.Add($"User with '{model.Username}' username already exists.");
            }

            if (this.dbcontext.Users.Any(u => u.Email == model.Email))
            {
                modelErrors.Add($"User with '{model.Email}' e-mail already exists.");
            }

            if (modelErrors.Any())
            {
                return(modelErrors);
            }

            var user = new User
            {
                Username = model.Username,
                Password = this.passwordHasher.HashPassword(model.Password),
                Email    = model.Email,
            };

            dbcontext.Users.Add(user);

            dbcontext.SaveChanges();

            return(modelErrors);
        }
Exemplo n.º 5
0
        public HttpResponse Register(UserCreateModel model)
        {
            var modelErrors = this.validator.ValidateUser(model);

            if (this.data.Users.Any(u => u.Username == model.Username))
            {
                modelErrors.Add("This username already exists!");
            }
            if (this.data.Users.Any(u => u.Email == model.Email))
            {
                modelErrors.Add("This email has already been used!");
            }

            if (modelErrors.Any())
            {
                return(Error(modelErrors));
            }

            var user = new User
            {
                Username = model.Username,
                Password = this.passwordHasher.HashPassword(model.Password),
                Email    = model.Email,
            };

            data.Users.Add(user);
            data.SaveChanges();

            return(Redirect("/Users/Login"));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Remove example
 /// </summary>
 /// <param name="id"></param>
 /// <param name="tuned"></param>
 /// <returns></returns>
 public bool RemoveResume(int id, bool tuned = false)
 {
     using (var context = new GitDbContext())
     {
         if (!tuned)
         {
             var item = context.GitHubResumes.Find(id);
             context.GitHubResumes.Remove(item);
             context.SaveChanges();
         }
         else
         {
             var item = new GitHubResume()
             {
                 Id = id
             };
             context.Entry(item).State = System.Data.Entity.EntityState.Deleted;
             context.SaveChanges();
         }
     }
     return(true);
 }
Exemplo n.º 7
0
        public HttpResponse Delete(string id)
        {
            var repositoryOwnerId = data.Commits.Where(x => x.Id == id).Select(x => x.Repository.OwnerId)
                                    .FirstOrDefault();

            if (repositoryOwnerId != User.Id)
            {
                return(Redirect("/Commits/All"));
            }
            var commit = data.Commits.Find(id);

            data.Commits.Remove(commit);
            data.SaveChanges();
            return(Redirect("/Repositories/All"));
        }
Exemplo n.º 8
0
        public void SeedLData(int amount = 1000)
        {
            var data = new List <LData>();

            for (var i = 0; i < amount; i++)
            {
                var item = new LData();
                item.Randomize();
                data.Add(item);
            }
            using (var context = new GitDbContext())
            {
                //context.BulkInsert(data);
                context.SaveChanges();
            }
        }
        public HttpResponse Create(RepositoriesCreateModel model)
        {
            var modelErrors = this.validator.ValidateRepository(model);

            if (modelErrors.Any())
            {
                return(Error(modelErrors));
            }

            var repo = new Repository()
            {
                Name      = model.Name,
                CreatedOn = DateTime.UtcNow,
                IsPublic  = model.RepositoryType == "Public", // potential error
                OwnerId   = User.Id
            };

            data.Repositories.Add(repo);

            data.SaveChanges();

            return(Redirect("/Repositories/All"));
        }