示例#1
0
        public string LoginWithMd5(string mobile, string password)
        {
            var returnData = new ReturnData();

            if (!string.IsNullOrEmpty(mobile) && !string.IsNullOrEmpty(password))
            {
                var userId = AccountBll.LoginWithMd5(mobile, password);
                if (!string.IsNullOrEmpty(userId))
                {
                    returnData.UserId        = userId.ToString();
                    returnData.Status        = "OK";
                    returnData.StatusContent = "登录成功";
                }
                else
                {
                    returnData.Status        = "FAIL";
                    returnData.StatusContent = "登录失败,请检查您的用户名和密码。";
                }
            }
            else
            {
                returnData.Status        = "PARAERROR";
                returnData.StatusContent = "参数错误";
            }
            return(_javaScriptSerializer.Serialize(returnData));
        }
示例#2
0
        /// <summary>
        /// New the account.
        /// </summary>
        /// <param name="personId">The person identifier.</param>
        /// <param name="balance">The balance.</param>
        /// <param name="typeId">The type identifier.</param>
        public void NewAccount(int personId, decimal balance, int typeId)
        {
            AccountBll temp = FactoryAccounts.CreateAccount(typeId, personId, generator.GenerateNumber(personId, balance, typeId), balance);

            accountRepository.Create(temp.ToDalAccount());
            context.Save();
        }
示例#3
0
        public static async Task <HttpResponseMessage> MarkupPage(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "MarkupPage/{pageName}")] HttpRequestMessage req,
            string pageName,
            TraceWriter log)
        {
            log.Info("appDeveloper: MarkupPage method started");
            var page       = InitPage(req);
            var accountBll = new AccountBll(new DatabaseHelper <Record>());

            var firstParameter  = req.GetQueryNameValuePairs().FirstOrDefault(q => q.Key == "m").Value;
            var secondParameter = req.GetQueryNameValuePairs().FirstOrDefault(q => q.Key == "n").Value;
            var clientLogin     = await GetClientLogin(req, accountBll);

            var initResponse = await InitResponse(page, clientLogin, pageName, firstParameter, accountBll);

            if (initResponse.IsNotValid)
            {
                return(page.RedirectResponse("Mistake"));
            }

            var processedWebPage = new ProcessedWebPage(page.t);
            var processedPage    =
                await processedWebPage.Get(pageName, page, initResponse, firstParameter, secondParameter);

            if (processedPage.IsPartial)
            {
                return(req.CreateResponse(HttpStatusCode.OK, processedPage.PageText));
            }

            var processedHeader =
                await processedWebPage.Get("LayoutHeader", page, initResponse, firstParameter, page.BrowserLocale);

            return(page.GetResponse(pageName, processedHeader.PageText, processedPage.PageText, processedPage.IsValidPage));
        }
示例#4
0
        public string UserInfo(string userId)
        {
            var returnData = new ReturnData();

            if (!string.IsNullOrEmpty(userId))
            {
                var account = AccountBll.GetUser(userId);
                if (!string.IsNullOrEmpty(userId))
                {
                    returnData.UserId        = account.Id.ToString();
                    returnData.UserNickName  = account.UserNickName;
                    returnData.UserHeadface  = account.UserHeadface;
                    returnData.Status        = "OK";
                    returnData.StatusContent = "登录成功";
                }
                else
                {
                    returnData.Status        = "FAIL";
                    returnData.StatusContent = "获取用户信息失败";
                }
            }
            else
            {
                returnData.Status        = "PARAERROR";
                returnData.StatusContent = "参数错误";
            }
            return(_javaScriptSerializer.Serialize(returnData));
        }
示例#5
0
 /// <summary>
 /// Closes the account.
 /// </summary>
 /// <param name="account">The account.</param>
 public void CloseAccount(AccountBll account)
 {
     Check(account);
     account.Close();
     accountRepository.Update(account.ToDalAccount());
     context.Save();
 }
示例#6
0
        public IHttpActionResult Register([FromBody] RegistrationUserModel user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                AccountBll.CreateAccount(user);
                var status = new MessageStatus()
                {
                    Code    = "200",
                    Message = "User was Created Succesfully"
                };
                return(Content(HttpStatusCode.OK, status, new JsonMediaTypeFormatter()));
            }
            catch (Exception e)
            {
                var status = new MessageStatus
                {
                    Code    = "500",
                    Message = e.Message
                };
                return(Content(HttpStatusCode.BadRequest, status, new JsonMediaTypeFormatter()));
            }
        }
示例#7
0
        public static async Task <HttpResponseMessage> Sign(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("appDeveloper: Sign method started");
            var page       = InitPage(req);
            var accountBll = new AccountBll(new DatabaseHelper <Record>());

            var tokenClientId = req.GetQueryNameValuePairs().FirstOrDefault(q => q.Key == "In").Value;

            if (string.IsNullOrEmpty(tokenClientId) ||
                !Guid.TryParse(tokenClientId, out var _))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, AValueIsInvalid));
            }

            //Check client permissions
            var userLogins = await accountBll.GetUserLogins(tokenClientId);

            if (!userLogins.Any())
            {
                return(page.RedirectResponse("Mistake"));
            }

            var returned = page.RedirectResponse("Index");

            returned.Headers.AddCookies(SetAuthCookie(req, tokenClientId, page.DebuggerIsAttached));
            return(returned);
        }
        /// <summary>
        /// To the BLL account.
        /// </summary>
        /// <param name="accountDal">The account DAL.</param>
        /// <returns>Equal BLL account.</returns>
        public static AccountBll ToBllAccount(this AccountDal accountDal)
        {
            AccountBll temp = FactoryAccounts.CreateAccount(accountDal.Type, accountDal.PersonId, accountDal.Number, accountDal.Balance);

            temp.Person = accountDal.Person.PartialMapPersonBll();

            return(temp);
        }
        /// <summary>
        /// To the DAL account.
        /// </summary>
        /// <param name="accountBll">The account BLL.</param>
        /// <returns>Equal DAL account.</returns>
        public static AccountDal ToDalAccount(this AccountBll accountBll)
        {
            AccountDal temp = new AccountDal(accountBll.PersoneId, accountBll.Number, accountBll.Balance,
                                             accountBll.Point, (int)accountBll.TypeId);

            temp.Person = accountBll.Person.PartialMapPersonDal();

            return(temp);
        }
示例#10
0
        public void Withdrawal_InvalidParams_ArgumentException()
        {
            IBankService service = GetKernel();

            service.NewAccount(1, 1000m, 1);
            List <AccountBll> storage = service.AllAccount().ToList();
            AccountBll        temp    = storage.Find(item => item.PersoneId == 1);

            Assert.Throws <ArgumentException>(() => service.Withdrawal(2000m, temp));
        }
示例#11
0
 /// <summary>
 /// Transfers the specified account.
 /// </summary>
 /// <param name="account">The account.</param>
 /// <param name="transfer">The transfer.</param>
 /// <param name="count">The count.</param>
 public void Transfer(AccountBll account, AccountBll transfer, decimal count)
 {
     Check(account);
     Check(transfer);
     account.Withdraw(count);
     transfer.Deposit(count);
     accountRepository.Update(account.ToDalAccount());
     accountRepository.Update(transfer.ToDalAccount());
     context.Save();
 }
示例#12
0
        /// <summary>
        /// Finds the specified account.
        /// </summary>
        /// <param name="number">The number.</param>
        /// <returns>Current account for predicate.</returns>
        /// <exception cref="ArgumentNullException">number</exception>
        public AccountBll FindAccount(int number)
        {
            AccountBll temp = accountRepository.Get(number).ToBllAccount();

            if (ReferenceEquals(temp, null))
            {
                throw new ArgumentNullException($"{nameof(number)} doesn't contains in the database");
            }

            return(temp);
        }
示例#13
0
        public void Withdrawal_ValidValue_ValidResult()
        {
            IBankService service = GetKernel();

            service.NewAccount(1, 2000m, 1);
            List <AccountBll> storage = service.AllAccount().ToList();
            AccountBll        temp    = storage.Find(item => item.PersoneId == 1);

            service.Withdrawal(1000m, temp);
            Assert.AreEqual(1000m, temp.Balance);
        }
示例#14
0
        public void Transfer_InvalidParams_ArgumentException()
        {
            IBankService service = GetKernel();

            service.NewAccount(2, 2000m, 1);
            service.NewAccount(1, 1000m, 1);
            List <AccountBll> storage       = service.AllAccount().ToList();
            AccountBll        firstPersone  = storage.Find(item => item.PersoneId == 1);
            AccountBll        secondPersone = storage.Find(item => item.PersoneId == 2);

            Assert.Throws <ArgumentException>(() => service.Transfer(secondPersone, firstPersone, 3000m));
        }
示例#15
0
        public void CloseAccount_ValidParams_ValidResult()
        {
            IBankService service = GetKernel();

            service.NewAccount(1, 1000m, 1);
            List <AccountBll> storage = service.AllAccount().ToList();
            AccountBll        temp    = storage.Find(item => item.PersoneId == 1);

            service.Withdrawal(1000m, temp);
            service.CloseAccount(temp);
            Assert.AreEqual(false, temp.Valid);
        }
示例#16
0
        /// <summary>
        /// Checks the specified account.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <exception cref="ArgumentNullException">account</exception>
        /// <exception cref="ArgumentException">account</exception>
        private void Check(AccountBll account)
        {
            if (ReferenceEquals(account, null))
            {
                throw new ArgumentNullException($"{nameof(account)} is null");
            }

            if (account.Valid == false)
            {
                throw new ArgumentException($"{nameof(account)} is closed");
            }
        }
示例#17
0
        /// <summary>
        /// Withdrawals the specified count.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="account">The account.</param>
        /// <exception cref="ArgumentException">count</exception>
        public void Withdrawal(decimal count, AccountBll account)
        {
            Check(account);
            if (count < 0)
            {
                throw new ArgumentException($"{nameof(count)} is less 0");
            }

            account.Withdraw(count);
            accountRepository.Update(account.ToDalAccount());
            context.Save();
        }
示例#18
0
        /// <summary>
        /// To the DAL account.
        /// </summary>
        /// <param name="accountBll">The account BLL.</param>
        /// <returns>Equal DAL account.</returns>
        public static AccountDal ToDalAccount(this AccountBll accountBll)
        {
            AccountDal temp = FactoryAccounts.CreateAccount(accountBll.TypeId);

            temp.Valid           = accountBll.Valid;
            temp.Number          = accountBll.Number;
            temp.Balance         = accountBll.Balance;
            temp.Point           = accountBll.Point;
            temp.PersonalInfo.Id = accountBll.PersoneId;

            return(temp);
        }
示例#19
0
        public void Transfer_ValidValue_ValidResult()
        {
            IBankService service = GetKernel();

            service.NewAccount(2, 2000m, 1);
            service.NewAccount(1, 1000m, 1);
            List <AccountBll> storage       = service.AllAccount().ToList();
            AccountBll        firstPersone  = storage.Find(item => item.PersoneId == 1);
            AccountBll        secondPersone = storage.Find(item => item.PersoneId == 2);

            service.Transfer(secondPersone, firstPersone, 500m);
            Assert.AreEqual(1500m, firstPersone.Balance);
        }
示例#20
0
        private static async Task <Login> GetClientLogin(HttpRequestMessage req, AccountBll accountBll)
        {
            var returned      = new Login();
            var tokenClientId = GetTokenClient(req);
            var userLogins    = await accountBll.GetUserLogins(tokenClientId);

            if (userLogins.Any())
            {
                returned.Client = userLogins.First();
            }
            returned.NotFound = !userLogins.Any() || string.IsNullOrEmpty(tokenClientId);

            return(returned);
        }
示例#21
0
        /// <summary>
        /// To the BLL account.
        /// </summary>
        /// <param name="accountDal">The account DAL.</param>
        /// <returns>Equal BLL account.</returns>
        public static AccountBll ToBllAccount(this AccountDal accountDal)
        {
            AccountBll temp = new AccountBll()
            {
                Id        = accountDal.Id,
                Number    = accountDal.Number,
                PersoneId = accountDal.PersonalInfo.Id,
                Point     = accountDal.Point,
                TypeId    = (int)accountDal.Type,
                Valid     = accountDal.Valid,
                Balance   = accountDal.Balance
            };

            return(temp);
        }
示例#22
0
        public ActionResult FindPwd(string phone, string pwd, string repwd, string code)
        {
            AccountBll       accountBll       = new AccountBll();
            SchoolTeacherBll schoolTeacherBll = new SchoolTeacherBll();
            bool             success          = false;
            string           msg        = "";
            bool             checkCode  = false;
            bool             checkPhone = false;
            bool             checkPwd   = false;
            DtoSchoolTeacher teacher    = null;

            try
            {
                checkCode = SmsCookie.GetSmsCode.Check(phone, code);
            }
            catch (Exception)
            {
                checkCode = false;
            }
            msg = checkCode ? "" : "验证码错误";
            if (checkCode)
            {
                teacher = schoolTeacherBll.GetSchoolTeacherByPhone(phone);
                if (teacher != null)
                {
                    checkPhone = true;
                    checkPwd   = !string.IsNullOrEmpty(pwd) && pwd == repwd;
                    msg        = checkPwd ? "" : "密码错误";
                }
                else
                {
                    msg        = "账号不存在";
                    checkPhone = false;
                }
            }
            if (checkCode && checkPhone && checkPwd)
            {
                success = schoolTeacherBll.UpdatePwd(teacher.Yoh_Id, Encrypt.GetMD5Pwd(pwd));
                msg     = success ? "修改成功" : "修改失败";
            }
            return(Json(new JsonSimpleResponse()
            {
                State = success, ErrorMsg = msg
            }));
        }
示例#23
0
        static void Main(string[] args)
        {
            kernel = new StandardKernel();
            kernel.ConfigurateResolver();
            IBankService service = kernel.Get <IBankService>();
            //service.NewOwner("Owner1", "Owner1", "123456", "*****@*****.**");
            //service.NewAccount(1, 1000m, 2);
            AccountBll temp = service.FindAccount(1158234195);

            Console.WriteLine(temp.Person.Name);

            PersonBll tempP = service.FindPerson("123456");

            //PersonBll person = service.FindPerson("123456");
            Console.WriteLine(tempP.Accounts.FirstOrDefault(item => item.Number == 1158234195).Number);

            //Console.WriteLine(account.PersoneId);
        }
示例#24
0
        protected override void ExcuteSelf()
        {
            try
            {
                DalInstance.WorkTaskDalInstance.Add(_WorkTask);

                if (_IfEmail)
                {
                    string        subject    = _WorkTask.Account.Name + "新增了一个工作计划";
                    List <string> to         = new List <string>();
                    AccountBll    accountBll = new AccountBll();
                    Account       account    = accountBll.GetLeaderByAccountId(_WorkTask.Account.Id);
                    account = DalInstance.AccountDalInstance.GetAccountById(account.Id);
                    if (account != null && account.Id > 0)
                    {
                        to.Add(account.Email1);
                        if (!string.IsNullOrEmpty(account.Email2))
                        {
                            to.Add(account.Email2);
                        }
                    }

                    for (int i = 0; i < _WorkTask.Responsibles.Count; i++)
                    {
                        Account responsible =
                            DalInstance.AccountDalInstance.GetAccountById(_WorkTask.Responsibles[i].Id);
                        if (responsible != null && responsible.Id > 0)
                        {
                            to.Add(responsible.Email1);
                            if (!string.IsNullOrEmpty(responsible.Email2))
                            {
                                to.Add(responsible.Email2);
                            }
                        }
                    }
                    new WorkTaskEmail(subject, WorkTaskEmail.BuildWorkTaskMailBody(_WorkTask).ToString(), to).SendMail();
                }
            }
            catch
            {
                throw MessageKeys.AppException(MessageKeys._DbError);
            }
        }
示例#25
0
        public static async Task <HttpResponseMessage> SignOut(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("appDeveloper: SignOut method started");
            var page       = InitPage(req);
            var accountBll = new AccountBll(new DatabaseHelper <Record>());

            //Check client permissions
            var clientLogin = await GetClientLogin(req, accountBll);

            if (clientLogin.NotFound)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, LoginNotFound));
            }

            var returned = page.RedirectResponse("SignIn?m=" + clientLogin.Client.CompanyId);

            returned.Headers.AddCookies(DeleteCookie(req, page.DebuggerIsAttached));
            return(returned);
        }
示例#26
0
        public string Register(string mobile, string nickname, string password)
        {
            var   returnData = new ReturnData();
            Regex regex      = new Regex("^1[34578]\\d{9}$");

            if (!regex.Match(mobile).Success)
            {
                returnData.Status        = "FAIL";
                returnData.StatusContent = "您输入的手机号码格式不正确。";
            }
            else
            {
                if (!string.IsNullOrEmpty(mobile) && !string.IsNullOrEmpty(password))
                {
                    string error;
                    var    result = AccountBll.Save(new AccountPostData()
                    {
                        UserMobile   = mobile,
                        UserPassword = password,
                        NickName     = nickname
                    }, out error);
                    if (result)
                    {
                        returnData.Status        = "OK";
                        returnData.StatusContent = "注册成功";
                    }
                    else
                    {
                        returnData.Status        = "FAIL";
                        returnData.StatusContent = error;
                    }
                }
                else
                {
                    returnData.Status        = "PARAERROR";
                    returnData.StatusContent = "参数错误";
                }
            }
            return(_javaScriptSerializer.Serialize(returnData));
        }
示例#27
0
        public IHttpActionResult Login([FromBody] UserLoginModel user)
        {       // If model is Invalid return failed login.
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (AccountBll.Login(user))
            {
                var jwtservice = new JWTService();
                var jwtmodel   = JWTModel.GetJWTContainerModel(user.Email);
                var token      = jwtservice.GenerateToken(jwtmodel);
                var dict       = new Dictionary <string, string>();
                dict.Add("token", token);
                return(Content(HttpStatusCode.OK, dict, new JsonMediaTypeFormatter()));
            }
            return(Content(HttpStatusCode.BadRequest, new MessageStatus()
            {
                Code = "500", Message = "Login Failed"
            },
                           new JsonMediaTypeFormatter()));
        }
示例#28
0
 public HttpResponseMessage UploadHeadFace()
 {
     try
     {
         HttpResponseMessage response = new HttpResponseMessage();
         var httpRequest = HttpContext.Current.Request;
         if (httpRequest.Files.Count > 0)
         {
             foreach (string file in httpRequest.Files)
             {
                 var postedFile = httpRequest.Files[file];
                 if (postedFile == null)
                 {
                     continue;
                 }
                 var filePath = HttpContext.Current.Server.MapPath("~/users/" + postedFile.FileName);
                 //先删除
                 if (File.Exists(filePath))
                 {
                     File.Delete(filePath);
                 }
                 postedFile.SaveAs(filePath);
                 AccountBll.UpdateHeadFace(postedFile.FileName.Replace(".jpg", string.Empty).Trim());
             }
         }
         return(response);
     }
     catch (Exception e)
     {
         //在webapi中要想抛出异常必须这样抛出,否则之抛出一个默认500的异常
         var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent(e.ToString()),
             ReasonPhrase = "error"
         };
         throw new HttpResponseException(resp);
     }
 }
示例#29
0
        public List <WorkTask> GetTeamWorkTaskByCondition(string creatorname, string deptname, string title, DateTime from, DateTime to,
                                                          int priority, bool ifNotStarted, bool ifOngoing, bool ifFailure, bool ifFinish, int accountID)
        {
            List <WorkTask> workTasks = new List <WorkTask>();
            Account         Leader    = new AccountBll().GetAccountById(accountID);

            if (Leader == null)
            {
                return(workTasks);
            }
            List <Account> accounts = new AccountBll().GetChargeAccountByNameAndDeptString(creatorname, deptname, Leader);

            for (int i = 0; i < accounts.Count; i++)
            {
                workTasks.AddRange(
                    DalInstance.WorkTaskDalInstance.GetMyWorkTaskByCondition(title, from, to, priority, ifNotStarted,
                                                                             ifOngoing, ifFailure, ifFinish,
                                                                             accounts[i].Id));
                workTasks.AddRange(
                    DalInstance.WorkTaskDalInstance.GetResponsibleWorkTaskByCondition(title, from, to, priority,
                                                                                      ifNotStarted,
                                                                                      ifOngoing, ifFailure, ifFinish,
                                                                                      accounts[i].Id));
            }
            for (int i = 0; i < workTasks.Count; i++)
            {
                for (int j = 0; j < workTasks.Count; j++)
                {
                    if (workTasks[i].Pkid == workTasks[j].Pkid && i != j)
                    {
                        workTasks.RemoveAt(j);
                        j--;
                    }
                }
                workTasks[i] = DalInstance.WorkTaskDalInstance.GetWorkTaskByPKID(workTasks[i].Pkid);
            }
            return(workTasks);
        }
示例#30
0
        private static async Task <InitResponse> InitResponse(KynodontasPage page, Login clientLogin, string pageName,
                                                              string firstParameter, AccountBll accountBll)
        {
            var returned = new InitResponse();

            //Check client permissions
            if (!page.Common.NonAuthPages.Contains(pageName) && clientLogin.NotFound)
            {
                return(new InitResponse {
                    IsNotValid = true
                });
            }

            var hasCompanyId = false;

            if (!clientLogin.NotFound)
            {
                returned.CompanyId   = clientLogin.Client.CompanyId;
                returned.ContactText = clientLogin.Client.ContactText;
                hasCompanyId         = true;
            }
            else if (pageName != "Mistake")
            {
                returned.CompanyId = new Guid(firstParameter).ToString();
                hasCompanyId       = true;
            }

            if (!hasCompanyId)
            {
                return(returned);
            }

            returned.CompanyName = "CompanyName";
            returned.ClientRole  = new ClientRole(11);
            return(returned);
        }