Ejemplo n.º 1
0
        public void TestToPublishedProject()
        {
            var model = new PublishedProjectBindingModel
            {
                Description = "desc",
                EndDate     = DateTimeOffset.UtcNow.AddDays(1.0),
                GoalIds     = new List <int> {
                    1
                },
                Name = "name",
                PointsOfContactIds = new List <int> {
                    2
                },
                Id = 3,
                ProjectStatusId = ProjectStatus.Completed.Id,
                StartDate       = DateTimeOffset.UtcNow.AddDays(-1.0),
                ThemeIds        = new List <int> {
                    4
                },
                ObjectiveIds = new List <int> {
                    5
                },
                CategoryIds = new List <int> {
                    6
                },
                LocationIds = new List <int> {
                    7
                },
                RegionIds = new List <int> {
                    8
                }
            };
            var user             = new User(1);
            var publishedProject = model.ToPublishedProject(user);

            Assert.AreEqual(user.Id, publishedProject.Audit.User.Id);
            Assert.AreEqual(model.Description, publishedProject.Description);
            Assert.AreEqual(model.EndDate, publishedProject.EndDate);
            Assert.AreEqual(model.Name, publishedProject.Name);
            Assert.AreEqual(model.Id, publishedProject.ProjectId);
            Assert.AreEqual(model.ProjectStatusId, publishedProject.ProjectStatusId);
            Assert.AreEqual(model.StartDate, publishedProject.StartDate);

            CollectionAssert.AreEqual(model.GoalIds.ToList(), publishedProject.GoalIds.ToList());
            CollectionAssert.AreEqual(model.PointsOfContactIds.ToList(), publishedProject.PointsOfContactIds.ToList());
            CollectionAssert.AreEqual(model.ThemeIds.ToList(), publishedProject.ThemeIds.ToList());
            CollectionAssert.AreEqual(model.ObjectiveIds.ToList(), publishedProject.ObjectiveIds.ToList());
            CollectionAssert.AreEqual(model.CategoryIds.ToList(), publishedProject.CategoryIds.ToList());
            CollectionAssert.AreEqual(model.LocationIds.ToList(), publishedProject.LocationIds.ToList());
            CollectionAssert.AreEqual(model.RegionIds.ToList(), publishedProject.RegionIds.ToList());
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutProjectAsync(PublishedProjectBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = userProvider.GetCurrentUser();
                var businessUser = userProvider.GetBusinessUser(currentUser);
                await projectService.UpdateAsync(model.ToPublishedProject(businessUser));

                await projectService.SaveChangesAsync();

                var dto = await projectService.GetProjectByIdAsync(model.Id);

                return(Ok(dto));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }