コード例 #1
0
        public IHttpActionResult Get()
        {
            var dealer    = _dealerServices.GetByUserId(UserId);
            var companies = _companyServices.GetByDealerId(dealer.Id);

            return(Ok(new
            {
                data = new
                {
                    companies
                }
            }));
        }
コード例 #2
0
        public IHttpActionResult GetForDealer()
        {
            var dealer = _dealerServices.GetByUserId(UserId);
            var orders = _orderService.GetByDealer(dealer.Id);

            return(Ok(new
            {
                data = new
                {
                    orders
                }
            }));
        }
コード例 #3
0
        public async Task <IHttpActionResult> Login(Auth auth)
        {
            try
            {
                var appUser = await _userManager.FindAsync(auth.UserName, auth.Password);

                if (appUser != null && appUser.Status == Enum.Status.Active)
                {
                    if (appUser.IsInRole(Enum.Role.Dealer))
                    {
                        var dealer = _dealerServices.GetByUserId(appUser.Id);
                        if (!dealer.Enable)
                        {
                            return(Content(HttpStatusCode.Forbidden, "This dealer is disabled"));
                        }
                    }

                    var isRememberMe = true;
                    Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    Authentication.SignIn(new AuthenticationProperties {
                        IsPersistent = isRememberMe
                    },
                                          await appUser.GenerateUserIdentityAsync(_userManager, DefaultAuthenticationTypes.ApplicationCookie, appUser));


                    return(Ok(new
                    {
                        data = new
                        {
                            user = appUser,
                            token = Guid.NewGuid().ToString()
                        }
                    }));
                }
                return(Ok(new
                {
                    data = new { error = "error" }
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }