public ActionResult Create(BranchModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var branch = model.ToEntity();
                branch.CreatedOnUtc = DateTime.UtcNow;
                _branchService.InsertBranch(branch);

                //search engine name
                model.SeName = branch.ValidateSeName(model.SeName, branch.Title, true);
                _urlRecordService.SaveSlug(branch, model.SeName, 0);

                //locales
                UpdateLocales(branch, model);
                _branchService.UpdateBranch(branch);

                SuccessNotification(_localizationService.GetResource("Toi.Plugin.Misc.Branches.Branch.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = branch.Id }) : RedirectToAction("List");
            }
            //parent branchGroups
            model.BranchGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
            if (model.BranchGroupId > 0)
            {
                var parentBranchGroup = _branchService.GetBranchGroupById(model.BranchGroupId);
                if (parentBranchGroup != null && !parentBranchGroup.Deleted)
                    model.BranchGroups.Add(new DropDownItem { Text = parentBranchGroup.GetFormattedBreadCrumb(_branchService), Value = parentBranchGroup.Id.ToString() });
                else
                    model.BranchGroupId = 0;
            }
            return View(model);
        }
Beispiel #2
0
        public async Task <IActionResult> AddBranchAsync([FromBody] BranchModel branch)
        {
            if (!await productsRepository.IsProductSellerAsync(branch.ProductId, int.Parse(User.Identity.Name)))
            {
                return(BadRequest());
            }

            return(Ok(await branchesRepository.AddBranchAsync(branch)));
        }
 public ActionResult Create()
 {
     ViewBag.AllLanguages = _languageService.GetAllLanguages(true);
     var model = new BranchModel();
     AddLocales(_languageService, model.Locales);
     model.Published = true;
     model.BranchGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
     return View(model);
 }
 public ActionResult BranchExcelFileImport(HttpPostedFileBase branchExcelFileBase)
 {
     if (ModelState.IsValid)
     {
         BranchModel branchModel = new BranchModel();
         branchModel.BranchExcelFile(branchExcelFileBase);
     }
     return(RedirectToAction("Index"));
 }
        public ActionResult Create()
        {
            BranchModel branchModel = new BranchModel()
            {
                IsActive = true
            };

            return(View(branchModel));
        }
Beispiel #6
0
        static Tuple <PullRequestDetailViewModel, IPullRequestService> CreateTargetAndService(
            string currentBranch    = "master",
            string existingPrBranch = null,
            bool prFromFork         = false,
            bool dirty   = false,
            int aheadBy  = 0,
            int behindBy = 0)
        {
            var repository         = Substitute.For <ILocalRepositoryModel>();
            var currentBranchModel = new BranchModel(currentBranch, repository);

            repository.CurrentBranch.Returns(currentBranchModel);
            repository.CloneUrl.Returns(new UriString(Uri.ToString()));

            var pullRequestService = Substitute.For <IPullRequestService>();

            if (existingPrBranch != null)
            {
                var existingBranchModel = new BranchModel(existingPrBranch, repository);
                pullRequestService.GetLocalBranches(repository, Arg.Any <IPullRequestModel>())
                .Returns(Observable.Return(existingBranchModel));
            }
            else
            {
                pullRequestService.GetLocalBranches(repository, Arg.Any <IPullRequestModel>())
                .Returns(Observable.Empty <IBranch>());
            }

            pullRequestService.Checkout(repository, Arg.Any <IPullRequestModel>(), Arg.Any <string>()).Returns(x => Throws("Checkout threw"));
            pullRequestService.GetDefaultLocalBranchName(repository, Arg.Any <int>(), Arg.Any <string>()).Returns(x => Observable.Return($"pr/{x[1]}"));
            pullRequestService.IsPullRequestFromFork(repository, Arg.Any <IPullRequestModel>()).Returns(prFromFork);
            pullRequestService.IsWorkingDirectoryClean(repository).Returns(Observable.Return(!dirty));
            pullRequestService.Pull(repository).Returns(x => Throws("Pull threw"));
            pullRequestService.Push(repository).Returns(x => Throws("Push threw"));
            pullRequestService.SwitchToBranch(repository, Arg.Any <IPullRequestModel>()).Returns(x => Throws("Switch threw"));

            var divergence = Substitute.For <BranchTrackingDetails>();

            divergence.AheadBy.Returns(aheadBy);
            divergence.BehindBy.Returns(behindBy);
            pullRequestService.CalculateHistoryDivergence(repository, Arg.Any <int>())
            .Returns(Observable.Return(divergence));

            var settings = Substitute.For <IPackageSettings>();

            settings.UIState.Returns(new UIState {
                PullRequestDetailState = new PullRequestDetailUIState()
            });

            var vm = new PullRequestDetailViewModel(
                repository,
                Substitute.For <IModelService>(),
                pullRequestService,
                settings);

            return(Tuple.Create(vm, pullRequestService));
        }
        public async Task <JsonResult> Delete([FromBody] BranchModel branchModel)
        {
            var brhFrontDeskAccounts = await _context.BrhFrontDeskAccounts.SingleOrDefaultAsync(m => m.FrontDeskAccountsId == branchModel.FrontDeskAccountsId);

            _context.BrhFrontDeskAccounts.Remove(brhFrontDeskAccounts);
            await _context.SaveChangesAsync();

            return(Json(new { brhFrontDeskAccounts }));
        }
    static TestData PrepareTestData(
        string repoName, string sourceRepoOwner, string sourceBranchName,
        string targetRepoOwner, string targetBranchName,
        string remote,
        bool repoIsFork, bool sourceBranchIsTracking)
    {
        var serviceProvider = Substitutes.ServiceProvider;
        var gitService = serviceProvider.GetGitService();
        var gitClient = Substitute.For<IGitClient>();
        var notifications = Substitute.For<INotificationService>();
        var host = Substitute.For<IRepositoryHost>();
        var api = Substitute.For<IApiClient>();
        var ms = Substitute.For<IModelService>();

        // this is the local repo instance that is available via TeamExplorerServiceHolder and friends
        var activeRepo = Substitute.For<ILocalRepositoryModel>();
        activeRepo.LocalPath.Returns("");
        activeRepo.Name.Returns(repoName);
        activeRepo.CloneUrl.Returns(new GitHub.Primitives.UriString("http://github.com/" + sourceRepoOwner + "/" + repoName));
        activeRepo.Owner.Returns(sourceRepoOwner);

        Repository githubRepoParent = null;
        if (repoIsFork)
            githubRepoParent = CreateRepository(targetRepoOwner, repoName, id: 1);
        var githubRepo = CreateRepository(sourceRepoOwner, repoName, id: 2, parent: githubRepoParent);
        var sourceBranch = new BranchModel(sourceBranchName, activeRepo);
        var sourceRepo = new RemoteRepositoryModel(githubRepo);
        var targetRepo = targetRepoOwner == sourceRepoOwner ? sourceRepo : sourceRepo.Parent;
        var targetBranch = targetBranchName != targetRepo.DefaultBranch.Name ? new BranchModel(targetBranchName, targetRepo) : targetRepo.DefaultBranch;

        activeRepo.CurrentBranch.Returns(sourceBranch);
        serviceProvider.GetRepositoryHosts().GitHubHost.Returns(host);
        host.ApiClient.Returns(api);
        host.ModelService.Returns(ms);
        api.GetRepository(Args.String, Args.String).Returns(Observable.Return(githubRepo));

        // sets up the libgit2sharp repo and branch objects
        var l2repo = SetupLocalRepoMock(gitClient, gitService, remote, sourceBranchName, sourceBranchIsTracking);

        return new TestData
        {
            ServiceProvider = serviceProvider,
            ActiveRepo = activeRepo,
            L2Repo = l2repo,
            SourceRepo = sourceRepo,
            SourceBranch = sourceBranch,
            TargetRepo = targetRepo,
            TargetBranch = targetBranch,
            GitClient = gitClient,
            GitService = gitService,
            NotificationService = notifications,
            RepositoryHost = host,
            ApiClient = api,
            ModelService = ms
        };
    }
Beispiel #9
0
 public ActionResult Edit(BranchModel branch)
 {
     if (ModelState.IsValid)
     {
         bool BranchEdit = Services.BranchService.Edit(branch);
         TempData["Success"] = "Data Saved Successfully!";
         return(RedirectToAction("Index", "Branch"));
     }
     return(View(branch));
 }
Beispiel #10
0
        public BranchModel Edit(BranchModel item)
        {
            var data = item.ConvertToData();

            using (_unitOfWorkFactory.Create())
            {
                _repository.Update(data);
            }
            return(data.ConvertToModel());
        }
Beispiel #11
0
        internal static MergeReport Build(BranchModel branch)
        {
            MergeReport result = new MergeReport();

            result.Timestamp    = DateTime.UtcNow;
            result.RepositoryId = branch.RepositoryId;
            result.BranchId     = branch.Id;
            result.Properties   = new List <MergeReport.Entry>();
            return(result);
        }
Beispiel #12
0
        public static Branch Map(BranchModel model, Branch destination)
        {
            destination.Id      = model.Id;
            destination.Name    = model.Name;
            destination.Address = model.Address;
            destination.Phone   = model.PhoneNumber;
            destination.Note    = model.Note;

            return(destination);
        }
        public async Task <ResultModel <BranchOutputModel> > InsertBranch([FromBody] BranchInputModel item)
        {
            var branchItem = new BranchModel()
            {
                Name        = item.Name,
                Description = item.Description
            };

            return(await _branchStoreService.InsertAndSaveAsync <BranchOutputModel>(branchItem));
        }
Beispiel #14
0
        public ActionResult Edit(Guid id)
        {
            BranchModel branch = new BranchModel(id);

            if (branch == null)
            {
                return(HttpNotFound());
            }
            return(View(branch));
        }
        public void AddBranch(BranchModel branch)
        {
            Branch new_branch = new Branch();

            new_branch.Name      = branch.Name;
            new_branch.LibraryId = 1; //----------------- TO DO
            new_branch.Location  = branch.Location;

            repositoryWrapper.BranchRepository.Create(new_branch);
        }
Beispiel #16
0
 public ActionResult DeleteConfirmed(BranchModel branch)
 {
     if (branch.Id > 0)
     {
         BranchModel BranchDelete = Services.BranchService.Delete(branch);
         TempData["Success"] = "Data Deleted Successfully!";
         return(RedirectToAction("Index", "Branch"));
     }
     return(View(branch));
 }
        public bool BranchCreation(BranchModel branchModel, string cudType)
        {
            Masbranch tempUser = null;

            try
            {
                if (branchModel != null && cudType != "D")
                {
                    if (branchModel.BrId == 0)
                    {
                        tempUser             = new Masbranch();
                        tempUser.Bid         = branchModel.Bid;
                        tempUser.BrName      = branchModel.BrName;
                        tempUser.BrAddressId = branchModel.BrAddressId;
                        tempUser.BrContactNo = branchModel.BrContactNo;
                        tempUser.BrEmailId   = branchModel.BrEmailId;
                        tempUser.BrManagerId = branchModel.BrManagerId;
                        tempUser.BrIsactive  = branchModel.BrIsactive;
                        tempUser.CreatedDate = branchModel.CreatedDate;
                        tempUser.CreatedBy   = branchModel.CreatedBy;
                        this.masbranchRepository.Add(tempUser);
                        unitOfWork.Commit();
                        return(true);
                    }
                    else
                    {
                        var userData = this.masbranchRepository.Get(exp => exp.BrId == branchModel.BrId && exp.BrIsactive == 1);
                        userData.BrId         = branchModel.BrId;
                        userData.Bid          = branchModel.Bid;
                        userData.BrName       = branchModel.BrName;
                        userData.BrAddressId  = branchModel.BrAddressId;
                        userData.BrContactNo  = branchModel.BrContactNo;
                        userData.BrEmailId    = branchModel.BrEmailId;
                        userData.BrManagerId  = branchModel.BrManagerId;
                        userData.BrIsactive   = branchModel.BrIsactive;
                        userData.ModifiedDate = branchModel.ModifiedDate;
                        userData.ModifiedBy   = branchModel.ModifiedBy;
                        masbranchRepository.Update(userData);
                        unitOfWork.Commit();
                        return(true);
                    }
                }
                else
                {
                    var userData = this.masbranchRepository.Get(exp => exp.Bid == branchModel.Bid);
                    userData.BrIsactive   = 0;
                    userData.ModifiedBy   = branchModel.ModifiedBy;
                    userData.ModifiedDate = branchModel.ModifiedDate;
                    masbranchRepository.Update(userData);
                    unitOfWork.Commit();
                    return(true);
                }
            }
            catch (Exception ex) { return(false); }
        }
Beispiel #18
0
        public async Task <BranchUserModel> GetBranchUserModel([FromBody] BranchUserSearchCriteriaModel criteria)
        {
            BranchUserModel branchUserModel = new BranchUserModel();
            BranchModel     branchObject    = await _branchService.FindById(criteria.BranchId);

            branchUserModel.BranchId   = branchObject.BranchId;
            branchUserModel.BranchName = branchObject.BranchName;
            branchUserModel.Users      = await GetIDMUsersSearch(criteria);

            return(branchUserModel);
        }
Beispiel #19
0
        /// <summary>
        /// 添加分公司休息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static Boolean AddbranchModify(SqlTransaction tran, BranchModel model)
        {
            SqlParameter[] para = new SqlParameter[] {
                new SqlParameter("@Number", SqlDbType.NVarChar, 50),
                new SqlParameter("@Name", SqlDbType.NVarChar, 50),
                new SqlParameter("@ForShort", SqlDbType.NVarChar, 250),
                new SqlParameter("@LinkMan", SqlDbType.NVarChar),
                new SqlParameter("@Mobile", SqlDbType.NVarChar, 50),
                new SqlParameter("@Telephone", SqlDbType.NVarChar, 50),
                new SqlParameter("@Fax", SqlDbType.NVarChar, 50),
                new SqlParameter("@Email", SqlDbType.NVarChar, 50),
                new SqlParameter("@Url", SqlDbType.NVarChar, 50),
                new SqlParameter("@CPCCode", SqlDbType.NVarChar, 10),
                new SqlParameter("@Address", SqlDbType.NVarChar, 500),
                new SqlParameter("@Bankcode", SqlDbType.NVarChar, 10),
                new SqlParameter("@BCPCCode", SqlDbType.NVarChar, 10),
                new SqlParameter("@BankAddress", SqlDbType.NVarChar, 500),
                new SqlParameter("@Bankuser", SqlDbType.NVarChar, 500),
                new SqlParameter("@BankNumber", SqlDbType.NVarChar, 50),
                new SqlParameter("@Remark", SqlDbType.Text),
                new SqlParameter("@OperateIP", SqlDbType.NVarChar, 30),
                new SqlParameter("@OperateNum", SqlDbType.NVarChar, 30),
                new SqlParameter("@regdate", SqlDbType.DateTime),
                new SqlParameter("@rowcount", SqlDbType.Int)
            };
            para[0].Value      = model.Number;
            para[1].Value      = model.Name;
            para[2].Value      = model.Forshort;
            para[3].Value      = model.Linkman;
            para[4].Value      = model.Mobile;
            para[5].Value      = model.Telephone;
            para[6].Value      = model.Fax;
            para[7].Value      = model.Email;
            para[8].Value      = model.Url;
            para[9].Value      = model.Cpccode;
            para[10].Value     = model.Address;
            para[11].Value     = model.Bankcode;
            para[12].Value     = model.Bcpccode;
            para[13].Value     = model.Bankaddress;
            para[14].Value     = model.Bankuser;
            para[15].Value     = model.Banknumber;
            para[16].Value     = model.Remark;
            para[17].Value     = model.Operaterip;
            para[18].Value     = model.Operatenum;
            para[19].Value     = DateTime.Now;
            para[20].Direction = ParameterDirection.Output;
            int i = DBHelper.ExecuteNonQuery(tran, "Add_proc_branch", para, CommandType.StoredProcedure);

            int id = Convert.ToInt32(DBHelper.ExecuteScalar(tran, "select id from branchmanage where branchnumber='" + model.Number + "'", CommandType.Text));

            string[] num = { "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "201", "202", "203", "204", "205", "206", "301", "302", "401", "402", "403", "404", "501", "502", "503", "504", "505", "506", "601", "602", "603", "604" };

            return(int.Parse(para[20].Value.ToString()) == 0 ? true : false);
        }
        public IHttpActionResult GetBranches()
        {
            var branches = new List <BranchModel>();

            foreach (var b in db.Branches.ToList())
            {
                var branch = new BranchModel(b.Index, b.Name, b.Address, b.Latitude, b.Longitude);
                branches.Add(branch);
            }
            return(Ok(branches));
        }
        public async Task <BranchModel> AddBranchAsync(BranchModel branch)
        {
            const string sql = "INSERT INTO dbo.Branches (Name, Description, ProductId, IsEnabled) " +
                               "OUTPUT INSERTED.Id, INSERTED.Name, INSERTED.Description, INSERTED.IsEnabled, INSERTED.CreateDate " +
                               "VALUES (@Name, @Description, @ProductId, @IsEnabled);";

            branch = await connection.QuerySingleAsync <BranchModel>(sql, branch);

            branch.Versions = new List <VersionModel>();
            return(branch);
        }
        public HttpResponseMessage Delete(BranchModel deleteBranch)
        {
            bool deleteResult = BranchManager.InsertUpdateDeleteBranches(deleteBranch);

            HttpStatusCode responseCode = deleteResult ? HttpStatusCode.OK : HttpStatusCode.BadRequest;

            return(new HttpResponseMessage(responseCode)
            {
                Content = new ObjectContent <bool>(deleteResult, new JsonMediaTypeFormatter())
            });
        }
        /*
         * Metodo que permite obter o identificador de um branch de um determinado processo, recebendo como argumento de entrada
         * o código correspondente ao branch do qual se pretende obter o modelo de dados. A lista de códigos é constituida por
         * { Dev : Desenvolvimento, Qa : Qualidade, Prod : Produção }
         */
        public string GetBranchID(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(string.Empty);
            }
            var         collection = _Database.GetCollection <BranchModel>("Branch");
            BranchModel branch     = collection.Find(s => s.Code == code).Single();

            return(branch.Id);
        }
Beispiel #24
0
        public async Task <IActionResult> PutBranchAsync([FromBody] BranchModel branch)
        {
            if (!await branchesRepository.IsBranchSellerAsync(branch.Id, int.Parse(User.Identity.Name)))
            {
                return(BadRequest());
            }

            await branchesRepository.UpdateBranchAsync(branch);

            return(Ok());
        }
Beispiel #25
0
        /// <summary>
        /// Gets the branches details.
        /// </summary>
        /// <param name="countryId">The country identifier.</param>
        /// <param name="cultureInfo">The culture information.</param>
        /// <returns></returns>
        public async Task GetBranchesDetails(int countryId, string cultureInfo)
        {
            try
            {
                SetActivityIndicatorBlurred(true);
                ActOpacity      = 1;
                MainStackLayout = false;
                PackingCygestPageLayoutOpacity = 0.4;
                Status = "Loading data...";
                var connected = CrossConnectivity.Current.IsConnected;

                if (connected)
                {
                    Branch = await _branchService.GetBranchDetailsAsync(countryId, cultureInfo, BrandId);

                    if (Branch.Count == 0 && _appViewModel.DefaultedCultureInfo != "fr-FR")
                    {
                        BranchModel tempBranch = new BranchModel
                        {
                            Id   = 0,
                            Code = "Unknown",
                            Name = "Unknown"
                        };
                        Branch.Add(tempBranch);
                    }
                    else
                    {
                        BranchModel tempBranch = new BranchModel
                        {
                            Id   = 0,
                            Code = "Inconnu",
                            Name = "Inconnu"
                        };
                        Branch.Add(tempBranch);
                    }

                    SetActivityIndicatorBlurred(false);
                    MainStackLayout = true;
                    PackingCygestPageLayoutOpacity = 1;
                    Status = "";
                }
            }
            catch (Exception e)
            {
                await _pageService.DisplayAlert(LblError, LblNoConnection, LblOk);

                DatabaseAccessAsync da = new DatabaseAccessAsync();
                da.InsertException(new PackingCygestExceptionModel
                {
                    Message = e.Message, StackTrace = e.StackTrace, TimeSpan = DateTime.Today.ToString(System.Globalization.CultureInfo.CurrentCulture), MethodName = e.Source
                });
            }
        }
 public IActionResult AddBranch(BranchModel branchModel)
 {
     try
     {
         BranchModel addedBranch = branchesLogic.AddBranch(branchModel);
         return(Created("https://localhost:44306/api/branches/" + branchModel.BranchId, branchModel));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Beispiel #27
0
        public void SetCurrentBranch(BranchModel currentBranch)
        {
            var teamProject = tfsVersionControlProvider.GetCurrentTeamProject();

            if (teamProject == null)
            {
                Debug.WriteLine("Could not find current team project.");
                return;
            }

            SetCurrentBranch(currentBranch, teamProject);
        }
Beispiel #28
0
 public IHttpActionResult Post(BranchModel model, int userId)
 {
     try
     {
         int result = _service.Insert(model, userId);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message.ToString()));
     }
 }
Beispiel #29
0
        public async Task <JsonResult> GetBranchDetails(string BranchId)
        {
            if (string.IsNullOrEmpty(BranchId))
            {
                return(Json(new BranchModel {
                    BranchIdString = BranchId
                }));
            }
            BranchModel result = await _ApiClient.GetAsync <BranchModel>("Branch/GetById/" + Util.Decrypt(BranchId), null);

            return(Json(result));
        }
Beispiel #30
0
        public bool EditBranch(BranchModel branchModel)
        {
            Branch branch = db.Branches.FirstOrDefault(b => b.Name == branchModel.Name);

            if (branch != null)
            {
                branch.Address = branchModel.Address;
                db.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #31
0
        private BranchModel Create(BranchModel item)
        {
            var data = item.ConvertToData();

            using (_unitOfWorkFactory.Create())
            {
                _repository.Add(data);
            }


            return(data.ConvertToModel());
        }
Beispiel #32
0
 public HttpResponseMessage Get(string branchName)
 {
     try
     {
         BranchModel branch = branchesManager.getBranchByName(branchName);
         return(Request.CreateResponse(HttpStatusCode.OK, branch));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
        public void UpdateBranch(BranchModel branch)
        {
            Branch updated_branch = new Branch();

            updated_branch = GetBranchByCondition(b => b.Name == branch.Name).First();
            if (branch.Location != null)
            {
                updated_branch.Location = branch.Location;
            }

            repositoryWrapper.BranchRepository.Update(updated_branch);
        }
        public PullRequestCreationViewModelDesigner()
        {
            Branches = new List<IBranch>
            {
                new BranchModel("master", new LocalRepositoryModel("http://github.com/user/repo")),
                new BranchModel("don/stub-ui", new LocalRepositoryModel("http://github.com/user/repo")),
                new BranchModel("feature/pr/views", new LocalRepositoryModel("http://github.com/user/repo")),
                new BranchModel("release-1.0.17.0", new LocalRepositoryModel("http://github.com/user/repo")),
            }.AsReadOnly();

            TargetBranch = new BranchModel("master", new LocalRepositoryModel("http://github.com/user/repo"));
            SourceBranch = Branches[2];

            SelectedAssignee = "Haacked (Phil Haack)";
            Users = new List<string>()
            {
                "Haacked (Phil Haack)",
                "shana (Andreia Gaita)"
            };
        }
    public void CreatePullRequestAllArgsMandatory()
    {
        var serviceProvider = Substitutes.ServiceProvider;
        var service = new PullRequestService(Substitute.For<IGitClient>(), serviceProvider.GetGitService(), serviceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());

        IRepositoryHost host = null;
        ILocalRepositoryModel sourceRepo = null;
        ILocalRepositoryModel targetRepo = null;
        string title = null;
        string body = null;
        IBranch source = null;
        IBranch target = null;

        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        host = serviceProvider.GetRepositoryHosts().GitHubHost;
        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        sourceRepo = new LocalRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff"), "c:\\path");
        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        targetRepo = new LocalRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff"), "c:\\path");
        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        title = "a title";
        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        body = "a body";
        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        source = new BranchModel("source", sourceRepo);
        Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));

        target = new BranchModel("target", targetRepo);
        var pr = service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body);

        Assert.NotNull(pr);
    }
 private void PrepareBranchModel(BranchModel model)
 {
     if (model == null)
     {
         throw new ArgumentNullException("BranchModel");
     }
     model.NumberOfAvailableGroups = _branchService.GetAllBranchGroups().Count;
 }
        static Tuple<PullRequestDetailViewModel, IPullRequestService> CreateTargetAndService(
            string currentBranch = "master",
            string existingPrBranch = null,
            bool prFromFork = false,
            bool dirty = false,
            int aheadBy = 0,
            int behindBy = 0)
        {
            var repository = Substitute.For<ILocalRepositoryModel>();
            var currentBranchModel = new BranchModel(currentBranch, repository);
            repository.CurrentBranch.Returns(currentBranchModel);
            repository.CloneUrl.Returns(new UriString(Uri.ToString()));

            var pullRequestService = Substitute.For<IPullRequestService>();

            if (existingPrBranch != null)
            {
                var existingBranchModel = new BranchModel(existingPrBranch, repository);
                pullRequestService.GetLocalBranches(repository, Arg.Any<IPullRequestModel>())
                    .Returns(Observable.Return(existingBranchModel));
            }
            else
            {
                pullRequestService.GetLocalBranches(repository, Arg.Any<IPullRequestModel>())
                    .Returns(Observable.Empty<IBranch>());
            }

            pullRequestService.Checkout(repository, Arg.Any<IPullRequestModel>(), Arg.Any<string>()).Returns(x => Throws("Checkout threw"));
            pullRequestService.GetDefaultLocalBranchName(repository, Arg.Any<int>(), Arg.Any<string>()).Returns(x => Observable.Return($"pr/{x[1]}"));
            pullRequestService.IsPullRequestFromFork(repository, Arg.Any<IPullRequestModel>()).Returns(prFromFork);
            pullRequestService.IsWorkingDirectoryClean(repository).Returns(Observable.Return(!dirty));
            pullRequestService.Pull(repository).Returns(x => Throws("Pull threw"));
            pullRequestService.Push(repository).Returns(x => Throws("Push threw"));
            pullRequestService.SwitchToBranch(repository, Arg.Any<IPullRequestModel>()).Returns(x => Throws("Switch threw"));

            var divergence = Substitute.For<BranchTrackingDetails>();
            divergence.AheadBy.Returns(aheadBy);
            divergence.BehindBy.Returns(behindBy);
            pullRequestService.CalculateHistoryDivergence(repository, Arg.Any<int>())
                .Returns(Observable.Return(divergence));

            var settings = Substitute.For<IPackageSettings>();
            settings.UIState.Returns(new UIState { PullRequestDetailState = new PullRequestDetailUIState() });

            var vm = new PullRequestDetailViewModel(
                repository,
                Substitute.For<IModelService>(),
                pullRequestService,
                settings);

            return Tuple.Create(vm, pullRequestService);
        }
        protected void UpdateLocales(Branch branch, BranchModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(branch,
                                                               x => x.Title,
                                                               localized.Title,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                          x => x.Short,
                                                          localized.MetaKeywords,
                                                          localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                          x => x.Full,
                                                          localized.MetaKeywords,
                                                          localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.SeName,
                                                           localized.SeName,
                                                           localized.LanguageId);
            }
        }
        public ActionResult Edit(BranchModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
                return AccessDeniedView();

            var branch = _branchService.GetBranchById(model.Id);
            if (branch == null)
                //No news item found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                branch = model.ToEntity(branch);
                _branchService.UpdateBranch(branch);

                //search engine name
                model.SeName = branch.ValidateSeName(model.SeName, branch.Title, true);
                _urlRecordService.SaveSlug(branch, model.SeName, 0);

                //locales
                UpdateLocales(branch, model);
                _branchService.UpdateBranch(branch);

                SuccessNotification(_localizationService.GetResource("Toi.Plugin.Misc.Branches.Branch.Updated"));
                return continueEditing ? RedirectToAction("Edit", new { id = branch.Id }) : RedirectToAction("List");
            }
            PrepareBranchModel(model);
            //parent branchGroups
            model.BranchGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
            if (model.BranchGroupId > 0)
            {
                var parentBranchGroup = _branchService.GetBranchGroupById(model.BranchGroupId);
                if (parentBranchGroup != null && !parentBranchGroup.Deleted)
                    model.BranchGroups.Add(new DropDownItem { Text = parentBranchGroup.GetFormattedBreadCrumb(_branchService), Value = parentBranchGroup.Id.ToString() });
                else
                    model.BranchGroupId = 0;
            }
            return View(model);
        }
Beispiel #40
0
        public void UpdateLocalesBranch(Branch branch, BranchModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(branch,
                                                               x => x.Name,
                                                               localized.Name,
                                                               localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.City,
                                                           localized.City,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.Address1,
                                                           localized.Address1,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(branch,
                                                           x => x.Address2,
                                                           localized.Address2,
                                                           localized.LanguageId);
            }
        }