Ejemplo n.º 1
0
        public async Task PostData(string team)
        {
            if (!myParent.IsConnected)
            {
                return;
            }

            var teamModel = new DataModels.Team
            {
                Name = team
            };

            try
            {
                var json = JsonConvert.SerializeObject(teamModel);
                var data = new StringContent(json, Encoding.UTF8, "application/json");

                var client = new HttpClient();

                var response = await client.PostAsync(myApiEndPoint, data);

                string result = response.Content.ReadAsStringAsync().Result;

                client.Dispose();
            }
            catch (Exception)
            {
                myParent.LosedConnection?.Invoke(this, new EventArgs());
            }
        }
Ejemplo n.º 2
0
        public static BusinessLayer.BusinessObjects.Team ToBusinessPlayer(this DataModels.Team team)
        {
            var businessModel = new BusinessLayer.BusinessObjects.Team
            {
                ID       = team.ID,
                TeamName = team.TeamName,
                Losts    = team.Losts,
                Wins     = team.Wins
            };

            return(businessModel);
        }
Ejemplo n.º 3
0
        public ViewModels.Team Save(ViewModels.RegisterTeam newTeam, string userName)
        {
            if (!ValidateTeam(newTeam, userName))
            {
                this.ValidationFailed();
                return(null);
            }

            this.ValidationPassed();
            DataModels.Team dbTeam = new DataModels.Team();
            dbTeam.Name             = newTeam.Name;
            dbTeam.PublicIdentifier = Guid.NewGuid();
            DataModels.User postingUser = this.context.User.Where(x => x.EmailAddress == userName).FirstOrDefault();
            dbTeam.Site        = postingUser.Site;
            dbTeam.Description = newTeam.Description;
            if (newTeam.TeamLeaderId != null)
            {
                DataModels.User teamLeader = this.context.User.Include(x => x.Role).Where(x => x.PublicIdentifier == newTeam.TeamLeaderId).FirstOrDefault();
                if (teamLeader != null)
                {
                    if (teamLeader.Role.ID == 4)
                    {
                        teamLeader.Role = this.context.Role.Where(x => x.ID == 3).FirstOrDefault();
                    }
                    dbTeam.TeamLeader = teamLeader;
                }
            }

            if (newTeam.TeamManagerId != null)
            {
                DataModels.User teamManager = this.context.User.Where(x => x.PublicIdentifier == newTeam.TeamManagerId).FirstOrDefault();
                if (teamManager != null)
                {
                    dbTeam.TeamManager = teamManager;
                }
            }

            dbTeam.TeamMembers = new List <DataModels.User>();

            foreach (RegisterMember member in newTeam.TeamMembers)
            {
                DataModels.User teamMember = this.context.User.Where(x => x.PublicIdentifier == member.Id).FirstOrDefault();
                dbTeam.TeamMembers.Add(teamMember);
            }

            this.context.Team.Add(dbTeam);
            this.context.SaveChanges();
            ViewModels.Team resultTeam = new ViewModels.Team();
            resultTeam.Name = dbTeam.Name;
            resultTeam.ID   = dbTeam.PublicIdentifier;
            return(resultTeam);
        }