public HttpResponse Create(RepositoryInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (input.Name.Length < 3 || input.Name.Length > 10) { return(this.Error("Invalid Repository name. The name should be between 3 and 10 characters.")); } if (string.IsNullOrEmpty(input.RepositoryType)) { return(this.Error("Repository type is required.")); } if (input.RepositoryType != "Public" && input.RepositoryType != "Private") { return(this.Error("Invalid repository type.")); } var userId = this.GetUserId(); this.repositoriesService.Create(input, userId); return(this.Redirect("/Repositories/All")); }
public void CreateRepository(string userId, RepositoryInputModel model) { var repository = new Repository { Name = model.Name, OwnerId = userId, CreatedOn = DateTime.UtcNow, IsPublic = model.RepositoryType == "Public" ? true : false }; this.dbContext.Repositories.Add(repository); this.dbContext.SaveChanges(); }
public void Create(RepositoryInputModel input, string userId) { var repository = new Repository { Name = input.Name, OwnerId = userId, IsPublic = false, CreatedOn = DateTime.UtcNow, }; if (input.RepositoryType == "Public") { repository.IsPublic = true; } this.db.Repositories.Add(repository); this.db.SaveChanges(); }
public HttpResponse Create(RepositoryInputModel model) { if (!this.User.IsAuthenticated) { return(this.Unauthorized()); } var errors = this.validator.ValidateRepository(model); if (errors.Any()) { return(this.Error(errors)); } var userId = this.User.Id; this.repositoryService.Add(model.Name, model.RepositoryType, userId); return(this.Redirect("/")); }
public HttpResponse Create(RepositoryInputModel model) { if (!IsUserSignedIn()) { return(this.Redirect("/")); } if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 3 || model.Name.Length > 10) { return(this.Error("Name should be between 3 and 10 characters long.")); } var userId = GetUserId(); this.repositoriesService.CreateRepository(userId, model); return(this.Redirect("/Repositories/All")); }
public HttpResponse Create(RepositoryInputModel repositoryInput) { if (!this.IsUserSignedIn()) { return(this.Redirect("/")); } if (repositoryInput.Name.Length < 3 || repositoryInput.Name.Length > 10 || string.IsNullOrWhiteSpace(repositoryInput.Name)) { return(this.Error("Repository name should be between 3 and 10 symbols!")); } if (string.IsNullOrWhiteSpace(repositoryInput.RepositoryType)) { return(this.Error("Repository type is required!")); } repositoriesService.Create(repositoryInput.Name, repositoryInput.RepositoryType, this.GetUserId()); return(this.Redirect("/Repositories/All")); }
public HttpResponse Create(RepositoryInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length < 3 || input.Name.Length > 10) { return(this.Error("Invalid repository name.")); } if (input.RepositoryType != "Public" && input.RepositoryType != "Private") { return(this.Error("Invalid repository type.")); } var userId = this.GetUserId(); this.repositoriesService.Add(input.Name, input.RepositoryType, userId); return(this.Redirect("/")); }
public HttpResponse Create(RepositoryInputModel model) { if (model.Name.Length < 3 || model.Name.Length > 10) { return(this.Error(ErrorConst.InvalidRepoName)); } var repository = new Repository { Name = model.Name, CreatedOn = DateTime.UtcNow, IsPublic = model.RepositoryType.ToLower() == "public" ? true : false, OwnerId = this.GetUserId(), }; bool result = this.repoService.Create(repository); if (!result) { return(this.Redirect(nameof(Create))); } return(this.Redirect(nameof(All))); }