/// <summary> /// 测试初始化 /// </summary> public DCRepositoriesServiceTest() { _scope = Ioc.BeginScope(); _dCRepositoriesRepository = _scope.Create <IDCRepositoriesRepository>(); _dCRepositoriesService = _scope.Create <IDCRepositoriesService>(); _dCRepositoriesDto = DCRepositoriesDtoTest.Create(); }
/// <summary> /// 转换为仓库表实体 /// </summary> /// <param name="dto">仓库表数据传输对象</param> public static DCRepositories ToEntity2(this DCRepositoriesDto dto) { if (dto == null) { return(new DCRepositories()); } return(new DCRepositories(dto.Id.ToGuid()) { DefaultBranch = dto.DefaultBranch, Description = dto.Description, IsMirror = dto.IsMirror.SafeValue(), IsPrivate = dto.IsPrivate.SafeValue(), Name = dto.Name, NumIssues = dto.NumIssues, NumOpenIssues = dto.NumOpenIssues, NumOpenPulls = dto.NumOpenPulls, NumPulls = dto.NumPulls, Size = dto.Size, UserID = dto.UserID, UserName = dto.UserName, CreationTime = dto.CreationTime, LastModifiTime = dto.LastModifiTime, IsDeleted = dto.IsDeleted.SafeValue(), Version = dto.Version, }); }
/// <summary> /// 转换为仓库表实体 /// </summary> /// <param name="dto">仓库表数据传输对象</param> public static DCRepositories ToEntity(this DCRepositoriesDto dto) { if (dto == null) { return(new DCRepositories()); } return(dto.MapTo(new DCRepositories(dto.Id.ToGuid()))); }
public async Task <IActionResult> Create(string name, string remoteurl, string description) { LibGit2Sharp.Repository result = null; name = name.Trim(); var UserName = string.Empty; var Uid = 0; var auth = await HttpContext.AuthenticateAsync(); UserName = HttpContext.User.Identity.Name; Uid = auth.Principal.Identities.First(u => u.IsAuthenticated).FindFirst(ClaimTypes.NameIdentifier).Value.ToInt(); var DCRepositoriesService = Ioc.Create <IDCRepositoriesService>(); var reps = await DCRepositoriesService.GetListByUserName(UserName); if (reps.Count > 9) { return(View(new { error = "已超过10个限制" })); } if (reps.Exists(r => r.Name == name)) { return(View(new { error = "已存在仓库" })); } if (!string.IsNullOrEmpty(name) && string.IsNullOrEmpty(remoteurl)) { result = DCRepositoriesService.CreateRepository(Path.Combine(UserName, name)); } else if (!string.IsNullOrEmpty(remoteurl)) { remoteurl = remoteurl.Trim(); result = DCRepositoriesService.CreateRepository(Path.Combine(UserName, name), remoteurl); } if (result != null) { var modelRep = new DCRepositoriesDto(); modelRep.Name = name; modelRep.Description = description; modelRep.CreatId = Uid; modelRep.CreationTime = DateTime.Now; modelRep.DefaultBranch = "master"; modelRep.UserName = UserName; modelRep.LastModifiTime = DateTime.Now; modelRep.LastModifiId = Uid; await DCRepositoriesService.CreateAsync(modelRep); return(Redirect("/")); } return(View()); }
public async Task <IActionResult> Create(string name, string remoteurl, string description) { LibGit2Sharp.Repository result = null; name = name.Trim(); var username = HttpContext.User.Identity.Name; var DCRepositoriesService = Ioc.Create <IDCRepositoriesService>(); var reps = await DCRepositoriesService.GetListByUserName(username); if (reps.Count > 9) { return(View(new { error = "已超过10个限制" })); } if (reps.Exists(r => r.Name == name)) { return(View(new { error = "已存在仓库" })); } if (!string.IsNullOrEmpty(name) && string.IsNullOrEmpty(remoteurl)) { result = DCRepositoriesService.CreateRepository(Path.Combine(username, name)); } else if (!string.IsNullOrEmpty(remoteurl)) { remoteurl = remoteurl.Trim(); result = DCRepositoriesService.CreateRepository(Path.Combine(username, name), remoteurl); } if (result != null) { var modelRep = new DCRepositoriesDto(); modelRep.Name = name; modelRep.Description = description; modelRep.CreationTime = DateTime.Now; modelRep.DefaultBranch = "master"; modelRep.UserName = username; modelRep.LastModifiTime = DateTime.Now; await DCRepositoriesService.CreateAsync(modelRep); return(Redirect("/")); } return(View()); }