Ejemplo n.º 1
0
        public JsonResult InviteUser(string UserName, int TeamID)
        {
            Team team = repository.Teams.FirstOrDefault(t => t.TeamID == TeamID);
            int userID = WebSecurity.GetUserId(UserName);
            UserProfile user = repository
                .Users
                .FirstOrDefault(u => u.UserId == userID);

            JsonResponse response = new JsonResponse();
            if (team == null || user == null)
            {
                response.Message = user == null ? "Неккоректное имя пользователя" : "Произошла ошибка";
                response.Success = false;
            }
            else
            {
                UserProfileTeam userProfileTeam = repository
                    .UserProfileTeam
                    .FirstOrDefault(ut => ut.UserID == userID && ut.TeamID == team.TeamID);

                if (userProfileTeam == null)
                {
                    userProfileTeam = new UserProfileTeam()
                        {
                            UserID = user.UserId,
                            TeamID = team.TeamID
                        };
                }

                userProfileTeam.Confirm = 0;
                repository.AddUserProfileTeam(userProfileTeam);

                response.Message = "Приглашение для " + UserName + " успешно отправлено";
                response.Success = true;
            }

            return Json(response, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 2
0
        public void DeleteUserProfileTeam(UserProfileTeam UserProfileTeam)
        {
            context.Entry(UserProfileTeam).State = EntityState.Deleted;

            context.SaveChanges();

            return;
        }
Ejemplo n.º 3
0
        public ActionResult CreateTeam(string TeamName)
        {
            int userID = WebSecurity.GetUserId(User.Identity.Name);
            UserProfile user = repository
                .Users
                .FirstOrDefault(u => u.UserId == userID);

            if (user == null)
            {
                logger.Warn("User with id = " + userID + " not found");
                throw new HttpException(404, "User with id = " + userID + " not found");
            }

            if (TeamName == null || TeamName == "")
            {
                return RedirectToAction("Team", new { Message = TeamMessageId.TeamNameIsNotDefined });
            }

            Team team = repository.Teams.FirstOrDefault(t => t.Name == TeamName);

            if (team != null)
            {
                return RedirectToAction("Team", new { Message = TeamMessageId.TeamAlreadyExist });
            }

            team = new Team() { Name = TeamName };

            repository.AddTeam(team);

            UserProfileTeam userProfileTeam = new UserProfileTeam() { UserID = userID, TeamID = team.TeamID, Confirm = 1 };

            repository.AddUserProfileTeam(userProfileTeam);

            return RedirectToAction("ManageTeam", new { ID = team.TeamID });
        }
Ejemplo n.º 4
0
        public int AddUserProfileTeam(UserProfileTeam UserProfileTeam)
        {
            if (UserProfileTeam.UserProfileTeamID == 0)
            {
                UserProfileTeam = context.UserProfileTeam.Add(UserProfileTeam);
            }
            else
            {
                context.Entry(UserProfileTeam).State = EntityState.Modified;
            }
            context.SaveChanges();
            context.Entry(UserProfileTeam).Reload();

            return UserProfileTeam.UserProfileTeamID;
        }