public IActionResult Register(Both newUser)
        {
            User user = newUser.user;

            if (ModelState.IsValid)
            {
                if (dbContext.Users.Any(u => u.Email == user.Email))
                {
                    ModelState.AddModelError("user.Email", "Email is already registered");
                    return(View("Index"));
                }
                else
                {
                    PasswordHasher <User> Hasher = new PasswordHasher <User>();
                    user.Password = Hasher.HashPassword(newUser.user, user.Password);
                    dbContext.Add(newUser.user);
                    dbContext.SaveChanges();
                    HttpContext.Session.SetInt32("UserId", user.UserId);
                    return(RedirectToAction("Success"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
        public async Task <IActionResult> Create([Bind("CustomerID,Name,Address,City,PostCode")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("BillPayID,Period,AccountNumber1,PayeeID,Amount,ScheduleDate,BillPayTimeUtc")] BillPay billPay)
        {
            if (ModelState.IsValid)
            {
                _context.Add(billPay);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(billPay));
        }
        public IActionResult processmoney(int Amount)
        {
            if (HttpContext.Session.GetInt32("id") == null)
            {
                return(RedirectToAction("Login"));
            }
            User user = dbContext.users.Include(p => p.Transactions).SingleOrDefault(u => u.userid == HttpContext.Session.GetInt32("id"));

            if (user.Sum + (decimal)Amount > 0)
            {
                Transaction trans = new Transaction {
                    amount = Amount, users_id = (int)HttpContext.Session.GetInt32("id")
                };
                dbContext.Add(trans);
                dbContext.SaveChanges();
            }
            return(RedirectToAction("Account"));
        }
Beispiel #5
0
 /// <summary>
 /// 增加柜台管理员
 /// </summary>
 /// <param name="manager">Mid,Mname,MPassword</param>
 public void AddData(Managers manager)
 {
     using (var dbContext = new bankContext())
     {
         //修改数据库信息最好有一些事务操作
         using (var transaction = dbContext.Database.BeginTransaction())
         {
             try
             {
                 dbContext.Add(manager);
                 dbContext.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message);
                 transaction.Rollback();
             }
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// 记录表Records中增加记录,该层为访问层,传入参数:DepositorAndCard,操作类型int v,double money, int mid
 /// </summary>
 /// <param name="dAndC">传入从cooike中获取的储户和储户银行卡信息。其对象为DepositorAndCard</param>
 /// <param name="v">出入参数v代表类型,1:代表取款,2:代表活期存款,其他:代表定期存款。每次传入一个类型的值,其他两项字段默认为0</param>
 /// <param name="money">金额</param>
 /// <param name="mid">业务办理员</param>
 public void AddData(DepositorAndCard dAndC, int icid, int v, double money, int mid)
 {
     using (var dbContext = new bankContext())
     {
         //修改数据库信息最好有一些事务操作
         using (var transaction = dbContext.Database.BeginTransaction())
         {
             try
             {
                 Records records = new Records();
                 records.Rcid  = (int)dAndC.Dcid;
                 records.Ruid  = dAndC.Duid;
                 records.Rmid  = mid;
                 records.Ricid = icid;
                 if (v == 1)
                 {
                     records.Rwithdrawals = money;
                 }
                 else if (v == 2)
                 {
                     records.RflowDeposit = money;
                 }
                 else
                 {
                     records.RfixDeposit = money;
                 }
                 dbContext.Add(records);
                 dbContext.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message);
                 transaction.Rollback();
             }
         }
     }
 }