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);
        }
示例#2
0
        public ICollection <string> ValidateRepository(RepositoryCreateFormModel model)
        {
            var errors = new List <string>();

            if (model.Name.Length < 3 || model.Name.Length > 10)
            {
                errors.Add("Name should be between 3 and 10 symbols");
            }

            return(errors);
        }
示例#3
0
        public HttpResponse Create(RepositoryCreateFormModel model)
        {
            string id = string.Empty;

            (var information, var isCorrect) = repositoriesService.CreateRepository(model, User.Id);

            if (!isCorrect)
            {
                return(this.Error(information));
            }

            id = information.FirstOrDefault();

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