/// <summary>
        /// Finds the organization category by name or create.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="name">The name.</param>
        /// <param name="iconUrl">The icon URL.</param>
        /// <param name="company">The company.</param>
        /// <param name="influencing">The influencing.</param>
        /// <param name="influencedBy">The influenced by.</param>
        /// <returns>OrganizationCategory.</returns>
        private static OrganizationCategory FindOrganizationCategoryByNameOrCreate(
            this ApplicationDbContext context,
            string name,
            string iconUrl,
            Company company,
            string influencing,
            string influencedBy)
        {
            var result = context.OrganizationCategories.FirstOrDefault(
                it => it.Name == name);

            if (result == null)
            {
                result = new OrganizationCategory()
                {
                    Name         = name,
                    Company      = company,
                    IconUrl      = iconUrl,
                    Influencing  = influencing,
                    InfluencedBy = influencedBy
                };
                context.OrganizationCategories.Add(result);
                context.SaveChanges();
            }
            return(result);
        }
        public void HasRoleInOrganizationOfType_Returns_False(OrganizationCategory unsupportedCategory)
        {
            //Arrange
            OrganizationCategory supportedCategory;

            switch (unsupportedCategory)
            {
            case OrganizationCategory.Other:
                supportedCategory = OrganizationCategory.Municipality;
                break;

            case OrganizationCategory.Municipality:
                supportedCategory = OrganizationCategory.Other;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(unsupportedCategory), unsupportedCategory, null);
            }

            SetupSut(categoryMap: new Dictionary <int, OrganizationCategory> {
                { _municipalityOrganizationId, supportedCategory }, { _otherOrgTypeOrganizationId, supportedCategory }
            });

            //Act
            var result = _sut.HasRoleInOrganizationOfType(unsupportedCategory);

            //Assert
            Assert.False(result);
        }
 /// <summary>
 /// GET /organizationcategories/{Id} 
 /// </summary>
 //[Authenticate]
 public object Get(OrganizationCategory organizationCategory)
 {
     return new OrganizationCategoryResponse
     {
         OrganizationCategory = Db.Id<OrganizationCategory>(organizationCategory.Id)
     };
 }
        public OrganizationCategory PostAddOrganizationCategory(OrganizationCategory orgCatRequest)
        {
            string url = $"api/OrganizationCategories";

            var organizationCategory = ApiHelper.CallPostWebApi <OrganizationCategory, OrganizationCategory>(url, orgCatRequest);

            return(organizationCategory);
        }
Ejemplo n.º 5
0
        private IOrganizationCategory GetNewOrganizationCategory()
        {
            IOrganizationCategory newOrganizationCategory;

            newOrganizationCategory             = new OrganizationCategory(GetUserContext());
            newOrganizationCategory.Name        = @"NewOrgCategory";
            newOrganizationCategory.Description = @"2 steg från Paradise";
            return(newOrganizationCategory);
        }
Ejemplo n.º 6
0
        public void updateTradingCategoriesForObject <T>(Session session, Guid supplierId, List <Guid> typeList)
        {
            try
            {
                T s = session.GetObjectByKey <T>(supplierId);
                if (s == null)
                {
                    throw new Exception("Key is not Exist in Org");
                }

                CriteriaOperator criteria =
                    new BinaryOperator("OrganizationId!Key", supplierId, BinaryOperatorType.Equal);
                XPCollection <OrganizationCategory> ocl = new XPCollection <OrganizationCategory>(session, criteria);

                foreach (OrganizationCategory oc in ocl)
                {
                    oc.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                    oc.Save();
                }

                foreach (Guid k in typeList)
                {
                    TradingCategory tc = session.GetObjectByKey <TradingCategory>(k);
                    if (tc == null)
                    {
                        throw new Exception("Key is not Exist in TradingCategory");
                    }

                    criteria = CriteriaOperator.And(
                        new BinaryOperator("OrganizationId", s, BinaryOperatorType.Equal),
                        new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater),
                        new BinaryOperator("TradingCategoryId", tc, BinaryOperatorType.Greater)
                        );

                    OrganizationCategory oc = session.FindObject <OrganizationCategory>(criteria);

                    if (oc == null)
                    {
                        oc                   = new OrganizationCategory(session);
                        oc.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                        oc.OrganizationId    = s as DAL.Nomenclature.Organization.Organization;
                        oc.TradingCategoryId = tc;
                        oc.Save();
                    }
                    else
                    {
                        oc.TradingCategoryId = tc;
                        oc.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                        oc.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void HasRoleIn_Returns_True_If_OrgId_Matches_Id_User_Is_Member_Of(OrganizationCategory category)
        {
            //Arrange
            var organizationId = GetOrganizationId(category);

            //Act
            var result = _sut.HasRoleIn(organizationId);

            //Assert
            Assert.True(result);
        }
 public ActionResult Add(OrganizationCategory orgCategory)
 {
     try
     {
         OrganizationCategoryService.Post(orgCategory);
         return RedirectToAction("Index", "OrganizationCategories");
     }
     catch (WebServiceException exception)
     {
         throw;
     }
 }
        public async Task <IActionResult> PutOrganizationCategory(int id, OrganizationCategory organizationCategory)
        {
            if (id != organizationCategory.OrganizationCategoryId)
            {
                return(BadRequest($"Invalid request. ID {id}, OrgCat {organizationCategory.OrganizationCategoryId}"));
            }

            if (!OrganizationCategoryExists(id))
            {
                return(BadRequest("Org Category Id does not exist"));
            }

            if (string.IsNullOrWhiteSpace(organizationCategory.CategoryName))
            {
                return(BadRequest("Category name cannot be empty"));
            }

            if (_context.OrganizationCategory.Any(x => x.OrganizationId == organizationCategory.OrganizationId &&
                                                  x.OrganizationCategoryId != organizationCategory.OrganizationCategoryId &&
                                                  x.CategoryName.Equals(organizationCategory.CategoryName)))
            {
                return(BadRequest("Category name already exists"));
            }

            if (string.IsNullOrWhiteSpace(organizationCategory.UserChanged))
            {
                return(BadRequest("User Login id cannot be empty"));
            }

            organizationCategory.DateChanged = DateTime.UtcNow;

            _context.Entry(organizationCategory).Property(x => x.CategoryName).IsModified = true;
            _context.Entry(organizationCategory).Property(x => x.DateChanged).IsModified  = true;
            _context.Entry(organizationCategory).Property(x => x.UserChanged).IsModified  = true;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrganizationCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        private int GetOrganizationId(OrganizationCategory category)
        {
            switch (category)
            {
            case OrganizationCategory.Other:
                return(_otherOrgTypeOrganizationId);

            case OrganizationCategory.Municipality:
                return(_municipalityOrganizationId);

            default:
                throw new ArgumentOutOfRangeException(nameof(category), category, null);
            }
        }
        public ActionResult Edit(OrganizationCategory orgCategory)
        {
            throw new NotImplementedException();
            //var client = GlobalHelper.GetClient(base.Session);

            //try
            //{
            //    client.Put(orgCategory);
            //    return RedirectToAction("Index", "OrganizationCategories");
            //}
            //catch (WebServiceException)
            //{
            //    throw;
            //}
        }
        /// <summary>
        /// Finds the organization by name or create.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="name">The name.</param>
        /// <param name="category">The category.</param>
        /// <param name="type">The type.</param>
        /// <param name="user">The user.</param>
        /// <param name="company">The company.</param>
        /// <param name="influencing">The influencing.</param>
        /// <param name="influencedBy">The influenced by.</param>
        /// <returns>Organization.</returns>
        private static Organization FindOrganizationByNameOrCreate(
            this ApplicationDbContext context,
            string name,
            OrganizationCategory category,
            OrganizationType type,
            ApplicationUser user,
            Company company,
            string influencing,
            string influencedBy)
        {
            var result = context.Organizations.FirstOrDefault(it => it.Name == name);

            if (result == null)
            {
                result = new Organization()
                {
                    Name         = name,
                    Type         = type,
                    Company      = company,
                    Category     = category,
                    InfluencedBy = influencing,
                    Influencing  = influencedBy,
                    User         = user
                };
                context.Organizations.Add(result);
                context.SaveChanges();
            }
            else
            {
                result.Type         = type;
                result.Company      = company;
                result.Category     = category;
                result.InfluencedBy = influencing;
                result.Influencing  = influencedBy;
                result.User         = user;
                context.SaveChanges();
            }

            return(result);
        }
 private IEnumerable <OrganizationRole> GetSupportedRoles(OrganizationCategory category)
 {
     return(_rolesPerOrganizationId[GetOrganizationId(category)]);
 }
        public async Task <ActionResult <OrganizationCategory> > PostOrganizationCategory(OrganizationCategory organizationCategory)
        {
            var existsOrganization = await _context.Organization
                                     .Where(x => x.OrganizationId == organizationCategory.OrganizationId)
                                     .FirstOrDefaultAsync();

            if (existsOrganization == null)
            {
                return(NotFound("Organization is either invalid/not found"));
            }

            if (string.IsNullOrWhiteSpace(organizationCategory.CategoryName))
            {
                return(BadRequest("Category name cannot be empty"));
            }
            else if (_context.OrganizationCategory.Any(x => x.OrganizationId == organizationCategory.OrganizationId &&
                                                       x.CategoryName.Equals(organizationCategory.CategoryName)))
            {
                return(BadRequest("Category name already exists"));
            }

            if (string.IsNullOrWhiteSpace(organizationCategory.UserAdded))
            {
                return(BadRequest("User added cannot be empty"));
            }

            organizationCategory.OrganizationCategoryId = await Utils.GetNextIdAsync(_context, "organization_category");

            organizationCategory.DateAdded = DateTime.UtcNow;
            organizationCategory.IsActive  = 1;

            _context.OrganizationCategory.Add(organizationCategory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetOrganizationCategory", new { id = organizationCategory.OrganizationCategoryId }, organizationCategory));
        }
Ejemplo n.º 15
0
 public bool HasRoleInOrganizationOfType(OrganizationCategory category)
 {
     return(false);
 }
Ejemplo n.º 16
0
 public bool HasRoleInOrganizationOfType(OrganizationCategory category)
 {
     return(_membershipCategories.Contains(category));
 }
Ejemplo n.º 17
0
 private void ExpectUserHasRoleInOrganizationOfType(OrganizationCategory organizationCategory, bool value)
 {
     _userContextMock.Setup(x => x.HasRoleInOrganizationOfType(organizationCategory)).Returns(value);
 }
Ejemplo n.º 18
0
        public void GetCrossOrganizationReadAccess_Returns_Based_On_Role_And_Organization_Type(bool isGlobalAdmin, bool isRightsHolder, bool isStakeHolder, OrganizationCategory organizationCategory, CrossOrganizationDataReadAccessLevel expectedResult)
        {
            //Arrange
            ExpectUserIsGlobalAdmin(isGlobalAdmin);
            ExpectUserHasStakeHolderAccess(isStakeHolder);
            ExpectUserHasRoleInOrganizationOfType(OrganizationCategory.Municipality, organizationCategory == OrganizationCategory.Municipality);
            ExpectUserHasRoleInAnyOrganization(OrganizationRole.RightsHolderAccess, isRightsHolder);

            //Act
            var result = _sut.GetCrossOrganizationReadAccess();

            //Assert
            Assert.Equal(expectedResult, result);
        }
        public void HasRole_Returns_True_For_Supported_Roles_And_False_For_Unsupported(OrganizationCategory category)
        {
            //Arrange
            var organizationId = GetOrganizationId(category);
            var allRoles       = Enum.GetValues(typeof(OrganizationRole)).Cast <OrganizationRole>().ToList();
            var supportedRoles = GetSupportedRoles(category);

            //Act
            var results = allRoles.Select(role => new
            {
                Role           = role,
                Result         = _sut.HasRole(organizationId, role),
                ExpectedResult = supportedRoles.Contains(role)
            }).ToList();

            //Assert
            foreach (var result in results)
            {
                Assert.Equal(result.ExpectedResult, result.Result);
            }
        }
 public object Put(OrganizationCategory organizationCategory)
 {
     Db.Update(organizationCategory);
     //return new HttpResult {StatusCode = HttpStatusCode.NoContent};
     return new OrganizationCategoryResponse { OrganizationCategory = new OrganizationCategory() };
 }
 public object Post(OrganizationCategory organizationCategory)
 {
     Db.Insert(organizationCategory);
     //return new HttpResult(Db.GetLastInsertId(), HttpStatusCode.Created);
     return new OrganizationCategoryResponse { OrganizationCategory = new OrganizationCategory() };
 }
 public void HasRoleInOrganizationOfType_Returns_True(OrganizationCategory category)
 {
     Assert.True(_sut.HasRoleInOrganizationOfType(category));
 }
 public ActionResult Add()
 {
     var orgCategory = new OrganizationCategory();
     return View(orgCategory);
 }
        public void PutUpdateOrganizationCategory(int id, OrganizationCategory orgCatRequest)
        {
            string url = $"api/OrganizationCategories/{id}";

            var organizationCategory = ApiHelper.CallPutWebApi <OrganizationCategory, OrganizationCategory>(url, orgCatRequest);
        }
 public object Delete(OrganizationCategory organizationCategory)
 {
     Db.DeleteById<OrganizationCategory>(organizationCategory.Id);
     //return new HttpResult { StatusCode = HttpStatusCode.NoContent };
     return new OrganizationCategoryResponse { OrganizationCategory = new OrganizationCategory() };
 }
Ejemplo n.º 26
0
        public void UpdateOrganization()
        {
            Boolean               hasCollection;
            DateTime              validFromDate, validToDate;
            IAddress              address;
            ICountry              country;
            Int32                 administrationRoleId;
            IOrganization         organization;
            IOrganizationCategory organizationCategory;
            IPhoneNumber          phoneNumber;
            String                city, name, shortName, number,
                                  organizationCategoryName, organizationCategoryDescription,
                                  postalAddress1, postalAddress2, description, zipCode;

            // Test addresses.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                organization           = GetOneOrganization();
                address                = new Address(GetUserContext());
                city                   = "Uppsala";
                address.City           = city;
                country                = CoreData.CountryManager.GetCountry(GetUserContext(), CountryId.Sweden);
                address.Country        = country;
                postalAddress1         = "";
                address.PostalAddress1 = postalAddress1;
                postalAddress2         = "ArtDatabanken, SLU";
                address.PostalAddress2 = postalAddress2;
                zipCode                = "752 52";
                address.ZipCode        = zipCode;
                organization.Addresses.Add(address);
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.IsTrue(organization.Addresses.IsNotEmpty());
                Assert.AreEqual(1, organization.Addresses.Count);
                Assert.AreEqual(city, organization.Addresses[0].City);
                Assert.AreEqual(country.Id, organization.Addresses[0].Country.Id);
                Assert.AreEqual(postalAddress1, organization.Addresses[0].PostalAddress1);
                Assert.AreEqual(postalAddress2, organization.Addresses[0].PostalAddress2);
                Assert.AreEqual(zipCode, organization.Addresses[0].ZipCode);
            }

            // Test administration role id.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                organization         = GetOneOrganization();
                administrationRoleId = 42;
                organization.AdministrationRoleId = administrationRoleId;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(administrationRoleId, organization.AdministrationRoleId.Value);
            }

            // Test name.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                name              = @"Maria";
                organization      = GetOneOrganization();
                organization.Name = name;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(name, organization.Name);
            }


            // Test shortName.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                shortName              = @"Uppdaterat shortname";
                organization           = GetOneOrganization();
                organization.ShortName = shortName;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(shortName, organization.ShortName);
            }

            // Test phone numbers.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                organization        = GetOneOrganization();
                phoneNumber         = new PhoneNumber(GetUserContext());
                country             = CoreData.CountryManager.GetCountry(GetUserContext(), CountryId.Sweden);
                phoneNumber.Country = country;
                number             = "018-67 10 00";
                phoneNumber.Number = number;
                organization.PhoneNumbers.Add(phoneNumber);
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.IsTrue(organization.PhoneNumbers.IsNotEmpty());
                Assert.AreEqual(1, organization.PhoneNumbers.Count);
                Assert.AreEqual(country.Id, organization.PhoneNumbers[0].Country.Id);
                Assert.AreEqual(number, organization.PhoneNumbers[0].Number);
            }

            // Test description.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                description              = @"Hej hopp i lingonskogen";
                organization             = GetOneOrganization();
                organization.Description = description;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(description, organization.Description);
            }

            // Test HasCollection
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                hasCollection = true;
                organization  = GetOneOrganization();
                organization.HasSpeciesCollection = hasCollection;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(hasCollection, organization.HasSpeciesCollection);
            }

            // Test organization category.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                organizationCategoryDescription  = @"De svenska länsstyrelserna";
                organizationCategoryName         = @"Länsstyrelse";
                organizationCategory             = new OrganizationCategory(GetUserContext());
                organizationCategory.Id          = 3;
                organizationCategory.Name        = organizationCategoryName;
                organizationCategory.Description = organizationCategoryDescription;
                GetOrganizationManager().UpdateOrganizationCategory(GetUserContext(), organizationCategory);
                Assert.IsNotNull(organization);
                Assert.AreEqual(organizationCategoryDescription, organizationCategory.Description);
                Assert.AreEqual(organizationCategoryName, organizationCategory.Name);
            }

            // Test valid from date.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                validFromDate = new DateTime(2010, 6, 5);
                organization  = GetOneOrganization();
                organization.ValidFromDate = validFromDate;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(validFromDate, organization.ValidFromDate);
            }

            // Test valid to date.
            using (ITransaction transaction = GetUserContext().StartTransaction())
            {
                validToDate              = new DateTime(2010, 6, 5);
                organization             = GetOneOrganization();
                organization.ValidToDate = validToDate;
                GetOrganizationManager().UpdateOrganization(GetUserContext(), organization);
                Assert.IsNotNull(organization);
                Assert.AreEqual(validToDate, organization.ValidToDate);
            }
        }
Ejemplo n.º 27
0
        private void moveData(Session session)
        {
            try
            {
                session.BeginTransaction();
                CriteriaOperator               criteria = new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater);
                XPCollection <SupplierOrg>     sol      = new XPCollection <SupplierOrg>(session);
                XPCollection <TradingCategory> tcl      = new XPCollection <TradingCategory>(session, criteria);
                foreach (SupplierOrg so in sol)
                {
                    foreach (TradingCategory tc in tcl)
                    {
                        criteria = CriteriaOperator.And(
                            new BinaryOperator("OrganizationId", so, BinaryOperatorType.Equal),
                            new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater),
                            new BinaryOperator("TradingCategoryId", tc, BinaryOperatorType.Greater)
                            );

                        OrganizationCategory oc = session.FindObject <OrganizationCategory>(criteria);
                        if (oc == null)
                        {
                            oc                   = new OrganizationCategory(session);
                            oc.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                            oc.OrganizationId    = so;
                            oc.TradingCategoryId = tc;
                            oc.Save();
                        }
                        else
                        {
                            oc.RowStatus = Utility.Constant.ROWSTATUS_ACTIVE;
                            oc.Save();
                        }
                    }
                }

                XPCollection <CustomerOrg> col = new XPCollection <CustomerOrg>(session);
                foreach (CustomerOrg co in col)
                {
                    foreach (TradingCategory tc in tcl)
                    {
                        criteria = CriteriaOperator.And(
                            new BinaryOperator("OrganizationId", co, BinaryOperatorType.Equal),
                            new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater),
                            new BinaryOperator("TradingCategoryId", tc, BinaryOperatorType.Greater)
                            );

                        OrganizationCategory oc = session.FindObject <OrganizationCategory>(criteria);
                        if (oc == null)
                        {
                            oc                   = new OrganizationCategory(session);
                            oc.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                            oc.OrganizationId    = co;
                            oc.TradingCategoryId = tc;
                            oc.Save();
                        }
                        else
                        {
                            oc.TradingCategoryId = tc;
                            oc.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                            oc.Save();
                        }
                    }
                }
                session.CommitTransaction();
            }
            catch (Exception ex)
            {
                session.RollbackTransaction();
                throw ex;
            }
        }