public HttpResponse Create(CreateCommitFormModel model) { if (!this.data.Repositories.Any(r => r.Id == model.Id)) { return(NotFound()); } if (model.Description.Length < CommitMinDescription) { return(Error($"Commit description have be at least {CommitMinDescription} characters.")); } var commit = new Commit { Description = model.Description, RepositoryId = model.Id, CreatorId = this.User.Id }; this.data.Commits.Add(commit); this.data.SaveChanges(); return(Redirect("/Repositories/All")); }
public HttpResponse Create(CreateCommitFormModel model) { var errors = commitsService.CreateNewCommit(model, this.User.Id); if (errors.Count != 0) { return(Error(errors)); } return(Redirect("/Repositories/All")); }
public List <string> CreateNewCommit(CreateCommitFormModel model, string userId) { ICollection <string> modelErrors = Validator.ValidateModel(model); if (!this.Data.Repositories.Any(r => r.Id == model.Id)) { modelErrors.Add("Already Exists"); } var commit = new Commit { Description = model.Description, RepositoryId = model.Id, CreatorId = userId }; this.Data.Commits.Add(commit); this.Data.SaveChanges(); return(modelErrors.ToList()); }