public ActionResult Create(RepositoryModel model) { if (ModelState.IsValid) { bool badName; var repo = RepositoryService.Create(model, Token.UserID, out badName); if (repo != null) { var success = GitService.CreateRepository(model.Name); if (!success) { RepositoryService.Delete(model.Name); repo = null; } } if (repo != null) { return RedirectToAction("Detail", "Repository", new { name = repo.Name }); } if (badName) ModelState.AddModelError("Name", SR.Repository_AlreadyExists); } return View(model); }
public RepositoryModel GetRepositoryModel(string name, bool withShipment = false) { using (var ctx = new GitCandyContext()) { var repo = ctx.Repositories.FirstOrDefault(s => s.Name == name); if (repo == null) return null; var model = new RepositoryModel { Name = repo.Name, Description = repo.Description, IsPrivate = repo.IsPrivate, AllowAnonymousRead = repo.AllowAnonymousRead, AllowAnonymousWrite = repo.AllowAnonymousWrite, }; if (withShipment) { model.Collaborators = repo.UserRepositoryRoles .Select(s => s.User.Name) .OrderBy(s => s, new StringLogicalComparer()) .ToArray(); model.Teams = repo.TeamRepositoryRoles .Select(s => s.Team.Name) .OrderBy(s => s, new StringLogicalComparer()) .ToArray(); } return model; } }
public ActionResult Create() { var model = new RepositoryModel { IsPrivate = false, AllowAnonymousRead = true, AllowAnonymousWrite = false, }; return View(model); }
public bool Update(RepositoryModel model) { using (var ctx = new GitCandyContext()) { var repo = ctx.Repositories.FirstOrDefault(s => s.Name == model.Name); if (repo != null) { repo.IsPrivate = model.IsPrivate; repo.AllowAnonymousRead = model.AllowAnonymousRead; repo.AllowAnonymousWrite = model.AllowAnonymousWrite; repo.Description = model.Description; ctx.SaveChanges(); return true; } return false; } }
public Repository Create(RepositoryModel model, long managerID, out bool badName) { using (var ctx = new GitCandyContext()) //using (TransactionScope transaction = new TransactionScope()) { badName = ctx.Repositories.Any(s => s.Name == model.Name); if (badName) return null; var repo = new Repository { Name = model.Name, Description = model.Description, CreationDate = DateTime.UtcNow, IsPrivate = model.IsPrivate, AllowAnonymousRead = model.AllowAnonymousRead, AllowAnonymousWrite = model.AllowAnonymousWrite, }; ctx.Repositories.Add(repo); ctx.SaveChanges(); if (managerID > 0) { repo.UserRepositoryRoles.Add(new UserRepositoryRole { Repository = repo, UserID = managerID, IsOwner = true, AllowRead = true, AllowWrite = true }); } ctx.SaveChanges(); //transaction.Complete(); return repo; } }
public ActionResult Edit(string name, RepositoryModel model) { if (string.IsNullOrEmpty(name)) throw new HttpException((int)HttpStatusCode.NotFound, string.Empty); if (ModelState.IsValid) { if (!RepositoryService.Update(model)) throw new HttpException((int)HttpStatusCode.NotFound, string.Empty); using (var git = new GitService(GitService.GetDirectoryInfo(name).FullName)) { git.SetHeadBranch(model.DefaultBranch); } return RedirectToAction("Detail", new { name }); } return View(model); }