Пример #1
0
        public void GetUsersDeepLoad()
        {
            var table = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);
            var user  = table.QueryByPartition(Settings.ApplicationIdentifier.ToString()).FirstOrDefault();

            if (null == user)
            {
                user = new UserData(string.Format("{0}@temp.com", Guid.NewGuid()), "na", Guid.NewGuid().ToBase64());
                table.AddEntity(user);
            }

            var companyTable = new AzureTable <CompanyRow>(CloudStorageAccount.DevelopmentStorageAccount);
            var companyRow   = new CompanyRow(user.Id)
            {
                Name = Guid.NewGuid().ToBase64(),
            };

            companyTable.AddEntity(companyRow);
            var roleTable = new AzureTable <RoleRow>(CloudStorageAccount.DevelopmentStorageAccount);
            var roleRow   = new RoleRow(Settings.ApplicationIdentifier)
            {
                UserIdentifier = user.Id,
                Name           = Guid.NewGuid().ToBase64(),
            };

            roleTable.AddEntity(roleRow);

            var core  = new ApplicationCore();
            var users = core.GetUsers(Application.Current, true);

            Assert.IsNotNull(users);
            Assert.IsTrue(0 < users.Count());
            var returned = (from data in users
                            where data.Identifier == user.Id &&
                            data.Companies != null &&
                            data.Roles != null
                            select data).FirstOrDefault();

            Assert.IsNotNull(returned);
            Assert.AreEqual <Guid>(user.Id, returned.Identifier);
            Assert.AreEqual <string>(user.UserName, returned.UserName);
            Assert.IsNotNull(returned.Companies);
            var company = (from data in returned.Companies
                           where data.Identifier == companyRow.Identifier
                           select data).First();

            Assert.AreEqual <Guid>(companyRow.Identifier, company.Identifier);
            Assert.AreEqual <string>(companyRow.Name, company.Name);
            Assert.IsNotNull(returned.Roles);

            var role = (from data in returned.Roles
                        where data == roleRow.Name
                        select data).First();

            Assert.AreEqual <string>(roleRow.Name, role);
        }
Пример #2
0
        public ActionResult Users()
        {
            using (new PerformanceMonitor())
            {
                try
                {
                    var appInfo = new ApplicationInformation()
                    {
                        Identifier = ServerConfiguration.ApplicationIdentifier,
                    };
                    var users = appCore.GetUsers(appInfo, true);

                    return(this.Json(users, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    logger.Log(ex, EventTypes.Error, (int)Fault.Unknown);
                    return(this.Json(WebResponse.Bind((int)Fault.Unknown, ex.Message), JsonRequestBehavior.AllowGet));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// User to Application
        /// </summary>
        /// <remarks>
        /// GET: /Management/UserToApplication
        /// </remarks>
        /// <returns>Action Result</returns>
        public ActionResult UserToApplication()
        {
            using (new PerformanceMonitor())
            {
                if (User.Identity.IsManager())
                {
                    var appInfo = new ApplicationInformation()
                    {
                        Identifier = ServerConfiguration.ApplicationIdentifier,
                    };
                    var model = new UserApplicationModel()
                    {
                        Applications = this.GetApplications(),
                        Users        = appCore.GetUsers(appInfo),
                    };

                    return(this.View(model));
                }
                else
                {
                    return(this.RedirectToAction("Index", "Home"));
                }
            }
        }