Exemplo n.º 1
0
        public static Gamer CreateGamer(string gamerName, Project project)
        {
            if (gamerName.IsNullOrBlank())
                return null;

            var gamer = new Gamer();
            gamer.UniqueKey = gamerName;
            gamer.Project = project;
            if (project.Levels.IsNotEmpty())
            {
                gamer.CurrentLevel = project.Levels.Min();
            }

            return gamer;
        }
Exemplo n.º 2
0
        public void WhenSaveProjectWithUser_UserProjectsCollectionShouldContainsThisProject()
        {
            var user = new User();
            this.usersRepo.AddPhysically(user);
            var userId = user.Id;
            var project = new Project();
            project.User = user;
            this.projectsRepo.AddPhysically(project);
            var projectId = project.Id;
            this.projectsRepo.ClearContext();

            project = this.projectsRepo.GetById(projectId);
            user = this.usersRepo.GetById(userId);

            user.Projects.Should().Contain(project);
        }
Exemplo n.º 3
0
        public void WhenSaveProjectWithUser_ShouldSaveUser()
        {
            var user = new User();
            this.usersRepo.AddPhysically(user);
            var userId = user.Id;
            var project = new Project();
            project.User = user;
            this.projectsRepo.AddPhysically(project);
            var projectId = project.Id;
            this.projectsRepo.ClearContext();

            project = this.projectsRepo.GetById(projectId);
            user = this.usersRepo.GetById(userId);

            project.User.Should().Be.EqualTo(user);
        }
Exemplo n.º 4
0
        public ActionResult Save(int? projectId, string title)
        {
            if (title.IsNullOrBlank())
            {
                ModelState.AddGeneralError("Project name must be not empty");
                return this.RedirectToAction(x => x.Index());
            }

            var currentUser = this.usersRepository.GetCurrentUser();
            var existingProject = this.projectsRepository.FirstOrDefault(x => x.Title == title && x.User.Id == currentUser.Id);
            if (existingProject != null)
            {
                ModelState.AddGeneralError("Project with the same name alredy exist.");
                return this.RedirectToAction(x => x.Index());
            }

            Project project;

            if (!projectId.HasValue)
            {
                project = new Project();
                project.Title = title;
                project.UserKey = Guid.NewGuid();
                project.GamerKey = Guid.NewGuid();
                project.User = currentUser;
                this.projectsRepository.Add(project);
                this.projectsRepository.SaveChanges();
            }
            else
            {
                project = this.projectsRepository.GetById(projectId.Value);
                project.Title = title;
            }

            this.projectsRepository.SaveChanges();
            return this.RedirectToAction(x => x.Show(project.Id));
        }