Exemplo n.º 1
0
        public ActionResult AddRole(Role role)
        {
            RoleValidation validator = new RoleValidation();

            role.IsDelete = false;
            var results = validator.Validate(role);

            if (!results.IsValid)
            {
                return(OpeCur.AjaxMsgNOOK(results.Errors[0].ErrorMessage));
            }
            OpeCur.BllServices.RoleService.Insert(role);
            if (OpeCur.BllServices.SaveChange() > 0)
            {
                return(OpeCur.AjaxMsgOK("添加成功"));
            }
            return(OpeCur.AjaxMsgNOOK("添加失败"));
        }
Exemplo n.º 2
0
        private async Task <RoleValidation> CheckLicense(Licensing.User user)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
#if DEBUG
                    //httpClient.BaseAddress = new Uri("https://akchan.me/");
                    httpClient.BaseAddress = new Uri("http://localhost:5000/");
#else
                    httpClient.BaseAddress = new Uri("https://akchan.me/");
#endif
                    httpClient.DefaultRequestHeaders.Accept.Clear();
                    httpClient.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));


                    //var crypto = new ClsCrypto("lol");
                    //DateTime result;
                    //DateTime.TryParse(crypto.Encrypt(user.timeStamp.ToString()), out result);
                    //user.timeStamp = result;

                    using (var response = httpClient.PostAsJsonAsync("api/checkLicense", user).Result)
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            RoleValidation roleValidation = response.Content.ReadAsAsync <RoleValidation>().Result;
                            return(roleValidation);
                        }
                        else
                        {
                            Bot.Log("Can't connect to the license server.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorAndClose(ex.Message);
            }
            return(new RoleValidation());
        }