示例#1
0
        public HttpResponseMessage Join(int id, ServiceModel.JoinTeamViewModel joinTeamViewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToJson()));
            }

            //get team
            var team = GetTeam(id);

            var user = context.GetAll <DomainModel.User>()
                       .FirstOrDefault(u => u.Id == joinTeamViewModel.UserId);

            if (user == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid User"));
            }
            if (user.Teams.Any(ut => ut.TeamId == team.Id))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "User already added to team"));
            }

            var newTeamMember = new DomainModel.TeamUser(team, user);

            if (team.IsOpen)
            {
                newTeamMember.Status = DomainModel.TeamUserStatus.Approved;
            }
            team.Members.Add(newTeamMember);
            context.SaveChanges();

            return(ResourceOkResponse(team.MapToBasicServiceModel()));
        }
示例#2
0
        public HttpResponseMessage AddMember(int id, ServiceModel.AddMemberViewModel viewModel)
        {
            if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToJson())); }

            //get team
            var team = GetTeam(id);

            var user = context.GetAll<DomainModel.User>()
                              .FirstOrDefault(u => u.EmailAddress == viewModel.EmailAddress);

            if (user == null)
            {
                user = new DomainModel.User(viewModel.EmailAddress);
                context.Add(user);
            }

            if (user.Teams.Any(ut => ut.TeamId == team.Id)) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "User already added to team"));

            var newTeamMember = new DomainModel.TeamUser(team, user);
            var inviter = team.Members.FirstOrDefault(x => x.UserId == viewModel.AddedByUserId);

            if (inviter == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "User Not Allowed to Invite Members to this Team")); }

            if (team.IsOpen || (inviter != null && inviter.Role== DomainModel.TeamUserRole.Administrator))
            {
                newTeamMember.Status = DomainModel.TeamUserStatus.Approved;
            }

            emailService.InvitedToTeam(user, inviter.User, team).Send();

            team.Members.Add(newTeamMember);
            context.SaveChanges();

            return ResourceOkResponse(team.MapToBasicServiceModel());
        }
示例#3
0
        public void ChangeOwner(User newOwner)
        {
            this.Owner   = newOwner;
            this.OwnerId = newOwner.Id;
            var teamUser = new TeamUser(this, newOwner);

            teamUser.Status = TeamUserStatus.Approved;
            teamUser.Role   = TeamUserRole.Administrator;
            this.Members.Add(teamUser);
        }
 public static ServiceModel.TeamMemberBasic MapToBasicServiceModel(this DomainModel.TeamUser tm)
 {
     if (tm == null)
     {
         return(null);
     }
     return(new ServiceModel.TeamMemberBasic()
     {
         Id = tm.UserId,
         FullName = tm.User.FirstName + " " + tm.User.LastName,
         EmailAddress = tm.User.EmailAddress,
         ImagePath = tm.User.ImagePath ?? "/images/GenericUserImage.gif",
         Role = tm.Role.ToString()
     });
 }
示例#5
0
        public HttpResponseMessage Join(int id, ServiceModel.JoinTeamViewModel joinTeamViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpResponseMessage <JsonValue>(ModelState.ToJson(), HttpStatusCode.BadRequest));
            }

            var team = context.GetAll <DomainModel.Team>()
                       .FirstOrDefault(u => u.Id == id);

            if (team == null)
            {
                ModelState.AddModelError("", "Invalid Team");
                return(new HttpResponseMessage <JsonValue>(ModelState.ToJson(), HttpStatusCode.BadRequest));
            }

            var user = context.GetAll <DomainModel.User>()
                       .FirstOrDefault(u => u.Id == joinTeamViewModel.UserId);

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid User");
                return(new HttpResponseMessage <JsonValue>(ModelState.ToJson(), HttpStatusCode.BadRequest));
            }

            if (user.Teams.Any(ut => ut.TeamId == team.Id))
            {
                ModelState.AddModelError("", "User already added to team");
                return(new HttpResponseMessage <JsonValue>(ModelState.ToJson(), HttpStatusCode.BadRequest));
            }

            var newTeamMember = new DomainModel.TeamUser(team, user);

            if (team.IsOpen)
            {
                newTeamMember.Status = DomainModel.TeamUserStatus.Approved;
            }
            team.TeamMembers.Add(newTeamMember);
            context.SaveChanges();

            var sTeam    = team.MapToBasicServiceModel();
            var response = new HttpResponseMessage <ServiceModel.TeamBasic>(sTeam, HttpStatusCode.OK);

            response.Headers.Location = new Uri(Request.RequestUri, "/api/team/" + sTeam.Id.ToString());
            return(response);
        }
示例#6
0
        public HttpResponseMessage AddMember(int id, ServiceModel.AddMemberViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToJson()));
            }

            //get team
            var team = GetTeam(id);

            var user = context.GetAll <DomainModel.User>()
                       .FirstOrDefault(u => u.EmailAddress == viewModel.EmailAddress);

            if (user == null)
            {
                user = new DomainModel.User(viewModel.EmailAddress);
                context.Add(user);
            }

            if (user.Teams.Any(ut => ut.TeamId == team.Id))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "User already added to team"));
            }

            var newTeamMember = new DomainModel.TeamUser(team, user);
            var inviter       = team.Members.FirstOrDefault(x => x.UserId == viewModel.AddedByUserId);

            if (inviter == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "User Not Allowed to Invite Members to this Team"));
            }

            if (team.IsOpen || (inviter != null && inviter.Role == DomainModel.TeamUserRole.Administrator))
            {
                newTeamMember.Status = DomainModel.TeamUserStatus.Approved;
            }

            emailService.InvitedToTeam(user, inviter.User, team).Send();

            team.Members.Add(newTeamMember);
            context.SaveChanges();

            return(ResourceOkResponse(team.MapToBasicServiceModel()));
        }
示例#7
0
        public HttpResponseMessage Join(int id, ServiceModel.JoinTeamViewModel joinTeamViewModel)
        {
            if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToJson())); }

            //get team
            var team = GetTeam(id);

            var user = context.GetAll<DomainModel.User>()
                              .FirstOrDefault(u => u.Id == joinTeamViewModel.UserId);

            if (user == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid User")); }
            if (user.Teams.Any(ut => ut.TeamId == team.Id)) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "User already added to team")); }

            var newTeamMember = new DomainModel.TeamUser(team, user);
            if (team.IsOpen)
            {
                newTeamMember.Status = DomainModel.TeamUserStatus.Approved;
            }
            team.Members.Add(newTeamMember);
            context.SaveChanges();

            return ResourceOkResponse(team.MapToBasicServiceModel());
        }