Ejemplo n.º 1
0
        public void TestToEcaProgram()
        {
            var rowVersion = new byte[1] {
                (byte)0
            };

            var model = new ProgramBindingModel();

            model.Id = 100;
            model.ProgramStatusId = ProgramStatus.Active.Id;
            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"
                }
            };
            model.RowVersion = Convert.ToBase64String(rowVersion);
            var user = new User(1);

            var ecaProgram = model.ToEcaProgram(user);

            Assert.AreEqual(model.Description, ecaProgram.Description);
            Assert.AreEqual(model.EndDate, ecaProgram.EndDate);
            Assert.AreEqual(model.Name, ecaProgram.Name);
            Assert.AreEqual(model.OwnerOrganizationId, ecaProgram.OwnerOrganizationId);
            Assert.AreEqual(model.ParentProgramId, ecaProgram.ParentProgramId);
            Assert.AreEqual(model.Id, ecaProgram.Id);
            Assert.AreEqual(model.ProgramStatusId, ecaProgram.ProgramStatusId);
            Assert.AreEqual(model.StartDate, ecaProgram.StartDate);

            CollectionAssert.AreEqual(model.Goals, ecaProgram.GoalIds);
            CollectionAssert.AreEqual(model.Contacts, ecaProgram.ContactIds);
            CollectionAssert.AreEqual(model.Themes, ecaProgram.ThemeIds);
            CollectionAssert.AreEqual(model.Regions, ecaProgram.RegionIds);
            CollectionAssert.AreEqual(rowVersion, ecaProgram.RowVersion);
            CollectionAssert.AreEqual(model.Websites.Select(x => x.Value).ToList(), ecaProgram.Websites.Select(x => x.Value).ToList());
            Assert.AreEqual(user.Id, ecaProgram.Audit.User.Id);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutProgramAsync(ProgramBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = userProvider.GetCurrentUser();
                var businessUser = userProvider.GetBusinessUser(currentUser);
                await programService.UpdateAsync(model.ToEcaProgram(businessUser));

                await programService.SaveChangesAsync();

                var dto = await programService.GetProgramByIdAsync(model.Id);

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