public void Basic_AddStatusType()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
            Organization org = store.Organizations.First();

            Mock<AuthIdentityService> perms = new Mock<AuthIdentityService>();
            perms.Setup(f => f.HasPermission(PermissionType.AdminOrganization, org.Id)).Returns(true);

            // SETUP
            var controller = new OrganizationsController(perms.Object, new DataStoreFactory(store));
            var mocks = new ContextMocks(controller);
            mocks.Request.Setup(r => r.AcceptTypes).Returns(new[] { "application/json" });

            int beginCount = org.UnitStatusTypes.Count;

            // TEST
            UnitStatusType type = new UnitStatusType { Name = "Test Type", IsMissionQualified = false, IsActive = true };

            var dataResult = controller.SaveStatus(org.Id, type);
            var model = (SubmitResult<UnitStatusType>)dataResult.Data;

            // VERIFY
            Assert.AreEqual(0, model.Errors.Length);
            //Assert.AreEqual(robert.Id, model.Result.OrganizationId, "Org ID should have been populated");
            Assert.AreEqual(beginCount + 1, org.UnitStatusTypes.Count);

            UnitStatusType savedType = org.UnitStatusTypes.Single(f => f.Id == type.Id);
            Assert.AreEqual(type.Name, savedType.Name);
            Assert.AreEqual(type.IsActive, savedType.IsActive);
            Assert.AreEqual(type.IsMissionQualified, savedType.IsMissionQualified);
        }
 public void CopyFrom(UnitStatusType other)
 {
     this.Organization = other.Organization;
     this.Name = other.Name;
     this.IsActive = other.IsActive;
     this.IsMissionQualified = other.IsMissionQualified;
 }
        public ActionResult StatusManagement(Guid q)
        {
            if (!Permissions.HasPermission(PermissionType.ViewOrganizationDetail, q)) return GetLoginError();

            UnitStatusType model = new UnitStatusType();
            using (var ctx = GetRepository())
            {
                var org = ctx.Organizations.Single(f => f.Id == q);
                model.Organization = org;
                model.OrganizationId = org.Id;
            }

            return PartialView(model);
        }
        public DataActionResult SaveStatus(Guid q, UnitStatusType model)
        {
            if (!Permissions.HasPermission(PermissionType.AdminOrganization, q)) return GetLoginError();

            SubmitResult<UnitStatusType> result = new SubmitResult<UnitStatusType>();
            ModelState.Remove("Organization");
            if (ModelState.IsValid)
            {
                using (var ctx = GetRepository())
                {
                    var oldModel = ctx.Organizations.Where(f => f.Id == q).SelectMany(f => f.UnitStatusTypes).SingleOrDefault(f => f.Id == model.Id);
                    if (oldModel == null)
                    {
                        ctx.Organizations.Single(f => f.Id == q).UnitStatusTypes.Add(model);
                    }
                    else
                    {
                        oldModel.CopyFrom(model);
                    }

                    ctx.SaveChanges();
                }
            }
            result.Result = model;
            return Data(result);
        }
        public ActionResult CreateStatus(Guid q)
        {
            if (!Permissions.HasPermission(PermissionType.AdminOrganization, q)) return GetLoginRedirect();

            UnitStatusType model;
            using (var ctx = GetRepository())
            {
                model = new UnitStatusType
                {
                    //Organization = (SarUnit)ctx.Organizations.Single(f => f.Id == q)
                };
            }
            ViewBag.OrgId = q;
            return PartialView("StatusForm", model);
        }