public AccountResult Create(AccountParam param)
        {
            Data.Entity.Account entity = AccountParamConverter.Convert(param, null);
            AccountDao.Save(entity);

            return(AccountResultConverter.Convert(entity));
        }
        public IActionResult GetToken([FromQuery] AccountParam param)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new{ msg = "参数验证失败" }));
            }

            if (param.UserAccount != "17623028800" || param.VerificationCode != "4566")
            {
                return(BadRequest(new { msg = "当前账号不存在" }));
            }

            //开始颁发token
            var claims = new Claim[]
            {
                new Claim(ClaimTypes.Name, "17623028800"),
                new Claim("admin", "true"),
                new Claim(ClaimTypes.Role, "admin"),
            };
            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtSeetings.SecretKey));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(_jwtSeetings.Issue, _jwtSeetings.Audience, claims, DateTime.Now,
                                             DateTime.Now.AddSeconds(20), creds);

            return(Ok(new{ Token = new JwtSecurityTokenHandler().WriteToken(token) }));
        }
Example #3
0
 public string Add(AccountParam model)
 {
     using (var t = _context.Database.BeginTransaction())
     {
         string check_status;
         try
         {
             if (GetAccountId(model.AcNumber) == 0)
             {
                 var account = new Account()
                 {
                     AcNumber   = model.AcNumber,
                     AcBalance  = 0,
                     AcName     = model.AcName,
                     AcIsActive = model.AcIsActive,
                     UserId     = model.UserId,
                 };
                 _context.Account.Add(account);
                 _context.SaveChanges();
                 check_status = Checkstatus.success;
             }
             else
             {
                 check_status = Checkstatus.duplicate_data;
             }
             t.Commit();
         }
         catch (Exception ex)
         {
             t.Rollback();
             check_status = Checkstatus.error;
         }
         return(check_status);
     }
 }
Example #4
0
        public AccountResult Create(AccountParam param)
        {
            Model.Account entity = ParamConverter.Convert(param, null);

            entity = Dao.Save(entity);

            return(ResultConverter.Convert(entity));
        }
Example #5
0
        public IActionResult Add([FromBody] AccountParam model)
        {
            string check_status;
            var    user_session = HttpContext.Session.GetString("usersession");

            check_status = accountRespository.Add(model);
            return(Json(check_status));
        }
Example #6
0
        public IActionResult Search([FromBody] AccountParam model)
        {
            //if (!ModelState.IsValid)
            //{

            //    return BadRequest(ModelState);
            //}
            //var user_session = HttpContext.Session.GetString("usersession");
            //var account_data = accountRespository.GetAccounts(1, model);
            var account_data = accountRespository.GetAccounts(model);

            return(Json(account_data));
        }
Example #7
0
        public void Update(long id, AccountParam param)
        {
            Data.Entity.Account oldEntity = Dao.Find(id);

            if (oldEntity != null)
            {
                Data.Entity.Account newEntity = ParamConverter.Convert(param, oldEntity);
                Dao.Update(newEntity);
            }
            else
            {
                throw new NullReferenceException();
            }
        }
Example #8
0
        public void updateStatus(AccountParam model)
        {
            //_context.Account.Attach(model);
            //EntityEntry<Account> entry = _context.Entry(model);
            //entry.State = EntityState.Modified;
            //_context.SaveChanges();

            var account = (from c in _context.Account
                           where c.AcId == model.AcId
                           select c).Single();

            account.AcIsActive = model.AcIsActive;
            _context.SaveChanges();
        }
Example #9
0
        public void Update(long id, AccountParam param)
        {
            Model.Account oldEntity = Dao.Find(id);

            if (oldEntity != null)
            {
                Dao.Delete(oldEntity);
                Dao.Update(ParamConverter.Convert(param, oldEntity));
            }
            else
            {
                Console.WriteLine($"No object with Id = {id}  was found");
            }
        }
Example #10
0
        public List <AccountViewModels> GetAccounts(AccountParam model)
        {
            IQueryable <AccountViewModels> queryResult = from a in _context.Account
                                                         where a.UserId == model.UserId && (a.AcNumber.Contains(model.AcNumber) || a.AcName.Contains(model.AcName))
                                                         select new AccountViewModels
            {
                AcId       = a.AcId,
                AcNumber   = a.AcNumber,
                AcName     = a.AcName,
                AcBalance  = a.AcBalance,
                AcIsActive = a.AcIsActive
            };

            return(queryResult.ToList());
        }
Example #11
0
        static void Main(string[] args)
        {
            AccountParam param = new AccountParam()
            {
                Id          = 5,
                Code        = "ivan code",
                Description = "Teacher account",
                Name        = "Ivan name",
                FirstName   = "Ivan",
                MiddleName  = "Georgiev",
                LastName    = "Marinov",
                Egn         = "1234567890",
                Address     = "kichuka",
                City        = "Plovdiv",
                Country     = "Bulgaria",
                HomePhone   = "032221144",
                MobilePhone = "08976654220",
                GenderType  = Gender.Male,
                Email       = "*****@*****.**",
                UserId      = 51,
                StatusId    = 5
            };

            AccountService service = new AccountService();

            Console.WriteLine("Create new Account :");
            Console.WriteLine(service.Create(param).Text);

            Console.WriteLine(new string('_', 80));

            Console.WriteLine("Listing all accounts :");
            Console.WriteLine(service.ListAll().Text);

            Console.WriteLine(new string('_', 80));

            Console.WriteLine("Find entity by PK :");
            Console.WriteLine(service.FindByPk(1).Text);

            Console.WriteLine(new string('_', 80));

            Console.WriteLine("Find entity by field :");
            Console.WriteLine(service.FindByField("FirstName", "Georgi").Text);

            Console.WriteLine(new string('_', 80));

            Console.ReadKey();
        }
Example #12
0
        static void GetParamInput(AccountParam param, string [] questions)
        {
            for (int i = 0; i < 9; i++)
            {
                Console.WriteLine(questions[i]);
                switch (i)
                {
                case 0:
                    param.Id = int.Parse(Console.ReadLine());
                    break;

                case 1:
                    param.Code = (Console.ReadLine());
                    break;

                case 2:
                    param.Name = Console.ReadLine();
                    break;

                case 3:
                    param.Description = Console.ReadLine();
                    break;

                case 4:
                    param.FirstName = Console.ReadLine();
                    break;

                case 5:
                    param.LastName = Console.ReadLine();
                    break;

                case 6:
                    param.Address = Console.ReadLine();
                    break;

                case 7:
                    param.Phone = Console.ReadLine();
                    break;

                case 8:
                    param.Email = Console.ReadLine();
                    break;
                }
                Console.WriteLine();
            }
            Console.WriteLine("--------------------------------------------");
        }
Example #13
0
        public IActionResult Register([FromBody] AccountParam param)
        {
            try
            {
                AuthProcessor.Register(param, Request);

                return(Ok("You have successfully managed to create an account. "));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public void Register(AccountParam param, HttpRequest request)
        {
            string[] credentials = GetHeaderCredentials(request);
            ValidateParameters(credentials[0], param.Email);

            UserParam userParam = new UserParam()
            {
                UserName = credentials[0],
                Password = credentials[1],
                StatusId = 1
            };
            UserResult user = UserProcessor.Create(userParam);

            param.UserId   = user.Id;
            param.StatusId = 1;
            _accountProcessor.Create(param);
        }
        public Response Create(AccountParam param)
        {
            Response response = new Response();

            try
            {
                response.Text   = "This account has been added :" + Environment.NewLine + JsonConverter.JsonConverter.ObjToJson(Processor.Create(param));
                response.Result = true;
            }
            catch (InvalidOperationException)
            {
                response.Text = "The user and/or status you've entered to the account do not exist in the system.";
            }
            catch (Exception)
            {
                response.Text   = "Unfortunately something went wrong. Are you sure that the entity you are trying to create doesn't already exist ?";
                response.Result = false;
            }
            return(response);
        }
Example #16
0
        /// <summary>
        /// Function to update information about a entity .
        /// </summary>
        /// <param name="id">entity's id</param>
        /// <param name="param">entity</param>
        /// <returns>response and update entity</returns>
        public ApiResponse Update(long id, AccountParam param)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Processor.Update(id, param);
                response.Result = true;
                response.Text   = "The entity updated successfully . \n";

                return(response);
            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Text   = ex.Message;

                return(response);
            }
        }
Example #17
0
        //public AccountService(IAccountProcessor processor)
        //{
        //    this.Processor = processor;
        //}

        /// <summary>
        /// Function to create new a entity .
        /// </summary>
        /// <param name="param">a entity</param>
        /// <returns>response and new entity</returns>
        public ApiResponse Create(AccountParam param)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                response.Text = $"The entity successfully added .\n" +
                                $" {Serialization.Serizlize(Processor.Create(param))}";
                response.Result = true;

                return(response);
            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Text   = ex.Message;

                return(response);
            }
        }
Example #18
0
        public ApiResponse Update(long id, AccountParam param)
        {
            AccountProcessor = new AccountProcessor();
            Response         = new ApiResponse();

            try
            {
                AccountProcessor.Update(id, param);
                Response.text   = "Entity was successfully updated";
                Response.result = true;

                return(Response);
            }
            catch (Exception e)
            {
                Response.text   = "Unfortunately something went wrong :(" + e;
                Response.result = false;

                return(Response);
            }
        }
Example #19
0
        public ApiResponse Create(AccountParam param)
        {
            AccountProcessor = new AccountProcessor();
            Response         = new ApiResponse();

            try
            {
                Response.text   = JsonConverter.JsonConverter.ObjToJson(AccountProcessor.Create(param));
                Response.result = true;

                return(Response);
            }

            catch (Exception e)
            {
                Response.text   = "Something went wrong :( " + e;
                Response.result = false;

                return(Response);
            }
        }
        public Response Update(long id, AccountParam param)
        {
            Response response = new Response();

            try
            {
                Processor.Update(id, param);
                response.Text   = "The entity has been updated.";
                response.Result = true;
            }
            catch (InvalidOperationException)
            {
                response.Text   = $"Entity status with id: {param.StatusId} (or user id: {param.UserId}) does not exist, therefore the update cannot execute.";
                response.Result = false;
            }
            catch (NullReferenceException)
            {
                response.Text   = $"Entity with id: {id} does not exist, therefore there is nothing to update.";
                response.Result = false;
            }
            return(response);
        }
Example #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="param">a entity</param>
 public void ValidateParameters(AccountParam param)
 {
     throw new NotImplementedException();
 }
        static void Main(string[] args)
        {
            AccountParam testParam = new AccountParam
            {
                FirstName       = "Lubo",
                Surname         = "Tapak",
                LastName        = "Tapak",
                Type            = "Idiot",
                Code            = "IDIOT",
                Description     = "Well, He is an idiot",
                Name            = "idiota",
                Id              = 3218985,
                AccountStatusId = 1,
                UserId          = 11
            };

            AccountService testService = new AccountService();

            Console.WriteLine("Adding an Account");

            ApiResponse response = testService.Create(testParam);

            Console.WriteLine(response.text);

            Console.WriteLine("_______________________________________________");
            Console.WriteLine("Listing all accounts");

            ApiResponse listAll = testService.ListAll();

            Console.WriteLine(listAll.text);

            Console.WriteLine("_______________________________________________");
            Console.WriteLine("Removing an account");

            ApiResponse deleteItem = testService.DeleteById(2);

            Console.WriteLine(deleteItem.text);

            Console.WriteLine("_______________________________________________");

            Console.WriteLine("Finding Name: Gosho in accounts");

            ApiResponse findByFieldName = testService.FindByField("FirstName", "Gosho");

            Console.WriteLine(findByFieldName.text);

            Console.WriteLine("_______________________________________________");

            Console.WriteLine("Finding Lubo");

            ApiResponse findById = testService.FindByPK(testParam.Id);

            Console.WriteLine(findById.text);

            Console.WriteLine("_______________________________________________");

            Console.ReadLine();

            Assembly executing = Assembly.GetExecutingAssembly();

            // Array to store types of the assembly
            Type[] types = executing.GetTypes();
            foreach (var item in types)
            {
                // Display each type
                Console.WriteLine("Class : {0}", item.Name);

                // Array to store methods
                MethodInfo[] methods = item.GetMethods();
                foreach (var method in methods)
                {
                    // Display each method
                    Console.WriteLine("--> Method : {0}", method.Name);

                    // Array to store parameters
                    ParameterInfo[] parameters = method.GetParameters();
                    foreach (var arg in parameters)
                    {
                        // Display each parameter
                        Console.WriteLine("----> Parameter : {0} Type : {1}",
                                          arg.Name, arg.ParameterType);
                    }
                }

                PropertyInfo[] properties = item.GetProperties();

                foreach (var property in properties)
                {
                    // Display each method
                    Console.WriteLine("--> Property : {0}", property.Name);
                }
            }
            Console.ReadLine();
        }
Example #23
0
 public IActionResult updateStatus([FromBody] AccountParam model)
 {
     accountRespository.updateStatus(model);
     return(Json(Checkstatus.success));
 }
Example #24
0
 /// <summary>
 /// 获取用户下所有帐号(分页)
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public PagedResults <Account> GetAccountList(AccountParam param)
 {
     return(AdvQuery(param));
 }
Example #25
0
        static void Main(string[] args)
        {
            //string[] questions = new string[]
            //{
            //    "Please enter your accoun's ID:",
            //    "Enter your account's code",
            //    "Enter your account's name",
            //    "Enter your account's description",
            //    "Enter your first name",
            //    "Enter your last name",
            //    "Enter your address",
            //    "Enter your phone",
            //    "Enter your email"
            //};

            AccountParam substitute = new AccountParam()
            {
                Id          = 4,
                Code        = "random",
                Name        = "ThisIsATest",
                Description = "Testing for missing properties.",
                FirstName   = "Tester",
                LastName    = "For param conv",
                UserId      = 13,
                StatusId    = 12
            };

            AccountParam main = new AccountParam()
            {
                Id          = 4,
                Code        = "15",
                Name        = "Koko",
                Description = "Student account for me.",
                FirstName   = "Koko",
                LastName    = "Kokov",
                Address     = "Anonymous",
                Email       = "*****@*****.**",
                Phone       = "+359874225648",
                UserId      = 3,
                StatusId    = 3
            };

            AccountParam listItem1 = new AccountParam()
            {
                Id          = 44,
                Code        = "15",
                Name        = "Pecata",
                Description = "Student account for me.",
                FirstName   = "Petur",
                LastName    = "PEcov",
                Address     = "Anonymous",
                Email       = "*****@*****.**",
                Phone       = "+359874225648",
                UserId      = 1,
                StatusId    = 1
            };
            AccountParam listItem2 = new AccountParam()
            {
                Id          = 43,
                Code        = "15",
                Name        = "Jivko",
                Description = "Student account for me.",
                FirstName   = "Jivko",
                LastName    = "Jivkov",
                Address     = "Anonymous",
                Email       = "*****@*****.**",
                Phone       = "+359874225648",
                UserId      = 1,
                StatusId    = 1
            };


            AccountService service = new AccountService();

            Console.WriteLine(service.Create(main).Text);
            Console.WriteLine(service.FindByCode("f").Text);
            Console.WriteLine(service.ListAll().Text);
            Console.WriteLine(service.Update(new List <AccountParam> {
                listItem1, listItem2, substitute
            }).Text);
            Console.WriteLine(service.Create(new List <AccountParam> {
                main, substitute
            }).Text);
        }
 public void Update(long id, AccountParam param)
 {
     Data.Entity.Account oldEntity = AccountDao.Find(id);
     Data.Entity.Account newEntity = AccountParamConverter.Convert(param, null);
     AccountDao.Update(newEntity);
 }