Пример #1
0
        public void TestToDraftProgram()
        {
            var model = new DraftProgramBindingModel();

            model.Description = "desc";
            model.EndDate     = DateTimeOffset.UtcNow;
            model.Goals       = new List <int> {
                1
            };
            model.Name = "name";
            model.OwnerOrganizationId = 2;
            model.ParentProgramId     = 3;
            model.Contacts            = new List <int> {
                2
            };
            model.StartDate = DateTimeOffset.UtcNow;
            model.Themes    = new List <int> {
                3
            };
            model.Regions = new List <int> {
                4
            };
            model.Websites = new List <WebsiteBindingModel> {
                new WebsiteBindingModel {
                    Id = null, Value = "http://google.com"
                }
            };
            var user = new User(1);

            var draftProgram = model.ToDraftProgram(user);

            Assert.AreEqual(model.Description, draftProgram.Description);
            Assert.AreEqual(model.EndDate, draftProgram.EndDate);
            Assert.AreEqual(model.Name, draftProgram.Name);
            Assert.AreEqual(model.OwnerOrganizationId, draftProgram.OwnerOrganizationId);
            Assert.AreEqual(model.ParentProgramId, draftProgram.ParentProgramId);
            Assert.AreEqual(model.StartDate, draftProgram.StartDate);

            CollectionAssert.AreEqual(model.Goals, draftProgram.GoalIds);
            CollectionAssert.AreEqual(model.Contacts, draftProgram.ContactIds);
            CollectionAssert.AreEqual(model.Themes, draftProgram.ThemeIds);
            CollectionAssert.AreEqual(model.Regions, draftProgram.RegionIds);
            CollectionAssert.AreEqual(model.Websites.Select(x => x.Value).ToList(), draftProgram.Websites.Select(x => x.Value).ToList());
            Assert.AreEqual(user.Id, draftProgram.Audit.User.Id);
        }
Пример #2
0
        public async Task <IHttpActionResult> PostProgramAsync(DraftProgramBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = userProvider.GetCurrentUser();
                var businessUser = userProvider.GetBusinessUser(currentUser);
                var program      = await programService.CreateAsync(model.ToDraftProgram(businessUser));

                await programService.SaveChangesAsync();

                var dto = await programService.GetProgramByIdAsync(program.ProgramId);

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