private void AssertPersonalInfoModelEqualsCustomer(PersonInformationModel personInformation, Customer customer)
 {
     Assert.AreEqual(personInformation.FirstName, customer.FirstName);
     Assert.AreEqual(personInformation.LastName, customer.LastName);
     Assert.AreEqual(personInformation.Email, customer.Email);
     Assert.AreEqual(personInformation.CellPhone, customer.CellPhone);
 }
示例#2
0
        public IHttpActionResult GetUserInfo()
        {
            var externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);

            var model = new UserInfoViewModel
            {
                Email         = User.Identity.GetUserName(),
                HasRegistered = externalLogin == null,
                LoginProvider = externalLogin?.LoginProvider,
                Roles         = UserManager.GetRoles(User.Identity.GetUserId())
            };

            try
            {
                if (model.Roles[0] == "Tenant")
                {
                    var tenant   = Cad.FetchTenant(User.Identity.GetUserId());
                    var userinfo = new TenantInformationModel(model, tenant);
                    return(Ok <TenantInformationModel>(userinfo));
                }
                else if (model.Roles[0] == "BuildingManager")
                {
                    var bm       = Cad.FetchBuildingManager(User.Identity.GetUserId());
                    var userinfo = new PersonInformationModel(model, bm);
                    return(Ok <PersonInformationModel>(userinfo));
                }
            }
            catch (ConnectedApartmentsException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Ok <UserInfoViewModel>(model));
        }