コード例 #1
0
        public async Task <ViewResult> Edit(EditTeamModel model)
        {
            Team newTeam = model.Team;

            if (model.File != null)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(model.File.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)model.File.Length);
                }
                newTeam.Avatar = imageData;
            }

            _highProvider.UpdateTeam(newTeam.TeamId, newTeam);
            Team _team = await CurrentTeam();

            if (TempData != null)
            {
                TempData["message"] = $"{_team.Name} has been saved";
            }

            return(View("Index", new TeamMainInfo()
            {
                Team = _team,
                ShowConfirming = false,
                Cups = _highProvider.GetAllTournaments().ToList()
            }));
        }
コード例 #2
0
ファイル: ApiServiceTest.cs プロジェクト: nowgua/nowgua-net
        public async void CRUDTest()
        {
            var api = new ApiService(this.ConnectionSettings);

            // Create
            var model = new CreateTeamModel {
                Name = "Test " + Rand(), Description = "Description ..."
            };
            var createdTeam = await api.Post <CreateTeamModel, LabelIdModel <string> >("/api/1.0/teams", model);

            Assert.NotNull(createdTeam);
            Assert.NotEmpty(createdTeam.Id);

            // Read
            var team = await api.Get <TeamModel>($"/api/1.0/teams/{createdTeam.Id}");

            Assert.NotNull(team);
            Assert.NotEmpty(team.Name);
            Assert.Equal(model.Name, team.Name);
            Assert.Equal(model.Description, team.Description);

            // Edit
            var editModel = new EditTeamModel {
                Id = team.Id, Name = "Test 2 ", Description = "Description 2..."
            };
            await api.Put <EditTeamModel, LabelIdModel <string> >("/api/1.0/teams", editModel);

            // Read
            team = await api.Get <TeamModel>($"/api/1.0/teams/{editModel.Id}");

            Assert.NotNull(team);
            Assert.NotEmpty(team.Name);
            Assert.Equal(editModel.Name, team.Name);
            Assert.Equal(editModel.Description, team.Description);

            // Delete
            await api.Delete($"/api/1.0/teams/delete/{team.Id}");

            Thread.Sleep(2000);
            team = await api.Get <TeamModel>($"/api/1.0/teams/{editModel.Id}");

            Assert.NotNull(team);
        }