public void Test_Update()
        {
            BrokerBLL bll = new BrokerBLL(_unit);

            var b = bll.GetList().ToArray()[0];

            b.Owner = "2b658482-6a38-4ed3-b356-77fe9b1569f1";

            bll.Update(b);
        }
        public void Test_Create()
        {
            BrokerBLL bll = new BrokerBLL(_unit);

            Broker b = new Broker
            {
                Name        = "BellDirect",
                Description = "Bell Direct",
                Shortable   = false,
                MinFee      = 15,
                FeeRate     = 0.15
            };

            bll.Create(b);
        }
        public async Task <IHttpActionResult> Get()
        {
            List <Broker> slist = null;

            try
            {
                BrokerBLL bll = new BrokerBLL(_unit);

                slist = bll.GetList().ToList();
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(slist));
        }
        public async Task <IHttpActionResult> Get(int id)
        {
            Broker s = null;

            try
            {
                BrokerBLL bll = new BrokerBLL(_unit);

                s = bll.GetByID(id);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(s));
        }
        public async Task <IHttpActionResult> Delete(int id)
        {
            try
            {
                var currentUser = await GetCurrentUser();

                BrokerBLL bll = new BrokerBLL(_unit);

                bool isAdmin = await AppUserManager.IsInRoleAsync(currentUser.Id, "Admin");

                if (isAdmin)
                {
                    bll.Delete(id);
                }
                else
                {
                    var w = bll.GetByID(id);

                    if (w.Owner == currentUser.Id)
                    {
                        bll.Delete(id);
                    }
                    else
                    {
                        BadRequest("You don't have permission to delete this broker.");
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }


            return(Ok());
        }