public void TestUpdate()
        {
            RuleBLL bll = new RuleBLL(_unit);

            Rule r = bll.GetByID(1);

            r.Note = DateTime.Now.ToLongTimeString() + "test ";
            bll.Update(r);
        }
        public async Task <IHttpActionResult> Get(int id)
        {
            Rule s = null;

            try
            {
                var currentUser = await base.GetCurrentUser();

                RuleBLL bll = new RuleBLL(_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();

                RuleBLL bll = new RuleBLL(_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 rule.");
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok());
        }