Example #1
0
        public ResponseModel PutWallet([FromRoute] int id, [FromBody] Wallet wallet)
        {
            string name       = wallet.Name_Wallet;
            float  amount     = wallet.Amount_Wallet;
            string disciption = wallet.Description;
            Wallet walletFind = _context.Wallets.Where(m => m.Id_Wallet == id).FirstOrDefault();

            if (!ModelState.IsValid)
            {
                ResponseModel res = new ResponseModel("Update fail", null, "404");
                return(res);
            }

            if (walletFind == null)
            {
                ResponseModel res = new ResponseModel("Update fail", null, "404");
                return(res);
            }
            Income_Outcome income = new Income_Outcome();

            walletFind.Name_Wallet = name;
            walletFind.Description = disciption;
            if (amount < walletFind.Amount_Wallet)
            {
                income.Is_Come        = false;
                walletFind.Amount_now = walletFind.Amount_Wallet - amount;
            }
            else
            {
                income.Is_Come        = true;
                walletFind.Amount_now = amount - walletFind.Amount_Wallet;
            }
            walletFind.Amount_Wallet = amount;

            income.Amount           = amount;
            income.Description_come = "Cập nhật ví " + name;
            income.Id_type          = "16";
            income.Date_come        = DateTime.Today.ToString();
            income.WalletId_Wallet  = id.ToString();
            try
            {
                _context.Income_Outcomes.Add(income);
                _context.Wallets.Update(walletFind);
                _context.SaveChanges();
                ResponseModel res = new ResponseModel("Update success", null, "200");
                return(res);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WalletExists(id))
                {
                    ResponseModel res = new ResponseModel("Not found", null, "404");
                    return(res);
                }
                else
                {
                    throw;
                }
            }
        }
Example #2
0
        public ResponseModel PutPeriodic([FromRoute] int id, [FromBody] Periodic periodic)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel res = new ResponseModel("Fail", null, "200");
                return(res);
            }

            float    amount     = periodic.Amount_Per;
            string   disciption = periodic.Desciption;
            DateTime date_e     = periodic.date_e;
            DateTime date_s     = periodic.date_s;
            string   id_time    = periodic.id_Time;

            periodic            = _context.Periodic.Where(m => m.Id_Per == id).FirstOrDefault();
            periodic.Amount_Per = amount;
            periodic.Desciption = disciption;
            periodic.date_e     = date_e;
            periodic.date_s     = date_s;
            periodic.id_Time    = id_time;
            periodic.isComeback = false;
            //if (periodic.Id_Wallet == 0)
            //{
            //    periodic.Id_Wallet = 1;
            //}
            //if (periodic.Id_Cate == 0)
            //{
            //    periodic.Id_Cate = 1;
            //}
            //if (periodic.Id_Type == 0)
            //{
            //    periodic.Id_Type = 1;
            //}
            //if (periodic.id_Time == 0)
            //{
            //    periodic.id_Time = 1;
            //}
            try
            {
                _context.Entry(periodic).State = EntityState.Modified;
                _context.SaveChanges();
                ResponseModel res = new ResponseModel("Update success", null, "200");
                return(res);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PeriodicExists(id))
                {
                    ResponseModel res = new ResponseModel("Not found", null, "200");
                    return(res);
                }
                else
                {
                    throw;
                }
            }
        }
Example #3
0
        public ResponseModel PutBudget([FromRoute] int id, [FromBody] Budget budget)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel res = new ResponseModel("Fail", null, "200");
                return res;
            }

            float amount = budget.Amount_Budget;
            float remain = budget.Remain;
            DateTime date_e = budget.time_e;
            DateTime date_s = budget.time_s;
            bool isfinnish = budget.isFinnish;
            string idtime = budget.id_Time;
            budget = _context.Budget.Where(m => m.Id_Budget == id).FirstOrDefault();
            budget.Amount_Budget = amount;
            budget.time_e = date_e;
            budget.time_s = date_s;
            budget.isFinnish = isfinnish;
            budget.id_Time = idtime;
            //if (budget.Id_Wallet == 0)
            //{
            //    budget.Id_Wallet = 1;
            //}
            //if (budget.Id_Cate == 0)
            //{
            //    budget.Id_Cate = 1;
            //}
            //if (budget.Id_type == 0)
            //{
            //    budget.Id_type = 1;
            //}
            budget.Remain = budget.Amount_Budget;
            budget.isFinnish = false;
            try
            {
                _context.Entry(budget).State = EntityState.Modified;
                _context.SaveChanges();
                ResponseModel res = new ResponseModel("Update success", null, "200");
                return res;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BudgetExists(id))
                {
                    ResponseModel res = new ResponseModel("Not found", null, "200");
                    return res;
                }
                else
                {
                    throw;
                }
            }
        }
        public ResponseModel PutIncome_Outcome([FromRoute] int id, [FromBody] Income_Outcome income_Outcome)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel res = new ResponseModel("Update fail", null, "404");
                return(res);
            }

            float  amount     = income_Outcome.Amount;
            string date       = income_Outcome.Date_come;
            string desciption = income_Outcome.Description_come;
            bool   is_come    = income_Outcome.Is_Come;
            string id_cate    = income_Outcome.CategoryId_Cate;
            string id_loan    = income_Outcome.LoanId_Loan;
            string id_trip    = income_Outcome.TripId_Trip;
            string id_wallet  = income_Outcome.WalletId_Wallet;
            string id_type    = income_Outcome.Id_type;
            string id_bill    = income_Outcome.Id_Bill;
            string id_budget  = income_Outcome.Id_Budget;
            string id_per     = income_Outcome.Id_Per;

            income_Outcome.Amount           = amount;
            income_Outcome.Date_come        = date;
            income_Outcome.Description_come = desciption;
            income_Outcome.Is_Come          = is_come;
            income_Outcome.CategoryId_Cate  = id_cate.ToString();
            income_Outcome.LoanId_Loan      = id_loan.ToString();
            income_Outcome.TripId_Trip      = id_trip.ToString();
            income_Outcome.Id_Bill          = id_bill.ToString();
            income_Outcome.Id_Budget        = id_budget.ToString();
            income_Outcome.Id_Per           = id_per.ToString();
            income_Outcome.Id_type          = id_type.ToString();
            try
            {
                _context.Income_Outcomes.Update(income_Outcome);
                _context.Entry(income_Outcome).State = EntityState.Modified;
                _context.SaveChanges();
                ResponseModel res = new ResponseModel("Update success", null, "404");
                return(res);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Income_OutcomeExists(id))
                {
                    ResponseModel res = new ResponseModel("Not found", null, "404");
                    return(res);
                }
                else
                {
                    throw;
                }
            }
        }
Example #5
0
        public ResponseModel GetSavingWallet([FromQuery] string id)
        {
            var saving = _context.SavingWallet.Where(w => w.id_user.ToString() == id);
            var list   = new ArrayList();

            if (saving == null)
            {
                ResponseModel res1 = new ResponseModel("Saving wallets", null, "200");
                return(res1);
            }
            foreach (SavingWallet saving1 in saving)
            {
                if (DateTime.Parse(saving1.date_e) <= DateTime.Today)
                {
                    saving1.is_Finnish = true;
                    _context.SavingWallet.Update(saving1);
                }
            }
            _context.SaveChanges();
            var saving_ = _context.SavingWallet.Where(w => w.id_user.ToString() == id);

            foreach (SavingWallet savingWallet in saving_)
            {
                var log = from a in _context.SavingWallet
                          join b in _context.Bank
                          on a.id_bank equals b.Id_Bank.ToString()
                              where (a.id_saving == savingWallet.id_saving)
                          select new
                {
                    id_saving = a.id_saving,
                    name      = a.name_saving,
                    date_e    = a.date_e,
                    date_s    = a.date_s,
                    price     = a.price,
                    price_end = a.price_end,
                    is_Finish = a.is_Finnish,
                    name_bank = b.Name_Bank,
                    interest  = b.Interest,
                    id_user   = a.id_user
                };
                var get = log.Where(m => m.id_user.Equals(id)).AsEnumerable();
                foreach (object l in get)
                {
                    list.Add(l);
                }
            }
            ResponseModel res = new ResponseModel("Saving wallets", list, "200");

            return(res);
        }
Example #6
0
        public ResponseModel PostUser([FromBody] User user)
        {
            string User_Name = user.User_Name;
            string password  = user.Password;
            string full_name = user.FullName;
            //bool check_wallet = user.Check_Wallet;
            User user1 = _context.Users.Where(m => m.User_Name == user.User_Name).FirstOrDefault();

            if (user1 != null)
            {
                ResponseModel res = new ResponseModel("User has existed", null, "200");
                return(res);
            }
            else
            {
                user.User_Name    = User_Name;
                user.Password     = password;
                user.FullName     = full_name;
                user.Check_Wallet = false;
                _context.Users.Add(user);
                _context.SaveChanges();
                ResponseModel res = new ResponseModel("Create success", null, "200");
                return(res);
            }
        }
        public ResponseModel PostCategory([FromBody] Category category)
        {
            string       name         = category.NameCate;
            string       image        = category.ImageCate;
            int          id_type      = category.Id_type;
            UserCategory userCategory = new UserCategory();
            Category     category1    = _context.Categories.Where(m => m.NameCate == category.NameCate).FirstOrDefault();

            try
            {
                if (category1 == null)
                {
                    category.NameCate  = name;
                    category.ImageCate = image;
                    category.Id_type   = id_type;
                    _context.Categories.Add(category);
                    _context.SaveChanges();
                    ResponseModel res = new ResponseModel("Create success", null, "200");
                    return(res);
                }
                else
                {
                    ResponseModel res = new ResponseModel("Category has existed", null, "200");
                    return(res);
                }
            }
            catch
            {
                ResponseModel res = new ResponseModel("Create fail", null, "200");
                return(res);
            }
        }
        public ResponseModel PostCreateWallet([FromBody] CreateWallet createWallet)
        {
            int    user_Id = createWallet.User_Id;
            float  amount  = createWallet.Amount;
            Wallet insert  = new Wallet();
            var    check   = false;

            insert.Amount_Wallet  = amount;
            insert.User_Id        = user_Id.ToString();
            insert.Name_Wallet    = "Ví tiền mặt";
            insert.Description    = "";
            insert.Id_Type_Wallet = "1";
            User user = _context.Users.Where(x => x.User_Id == user_Id).FirstOrDefault();

            user.Check_Wallet = true;
            try
            {
                _context.Wallets.Add(insert);
                _context.Users.Update(user);
                _context.SaveChanges();
                check = true;
            }
            catch { check = false; }
            if (check == false)
            {
                ResponseModel res = new ResponseModel("Create fail", null, "404");
                return(res);
            }
            else
            {
                ResponseModel res = new ResponseModel("Create success", null, "200");
                return(res);
            }
        }
Example #9
0
        public ResponseModel PostTransactions([FromBody] Transactions transactions)
        {
            float        price        = transactions.price_trans;
            string       name         = transactions.name_trans;
            string       date         = transactions.date_trans;
            string       id_saving    = transactions.id_saving;
            bool         is_Income    = transactions.is_Income;
            SavingWallet savingWallet = _context.SavingWallet.Where(m => m.id_saving.ToString() == id_saving).FirstOrDefault();

            if (savingWallet == null)
            {
                ResponseModel res1 = new ResponseModel("Transactions fail", null, "404");
                return(res1);
            }
            transactions.price_trans = price;
            transactions.date_trans  = date;
            transactions.id_saving   = id_saving;
            transactions.is_Income   = is_Income;

            if (is_Income == true)
            {
                savingWallet.price = savingWallet.price + price;
            }
            if (is_Income == false)
            {
                savingWallet.price = savingWallet.price - price;
            }
            _context.SavingWallet.Update(savingWallet);
            _context.Transactions.Add(transactions);
            _context.SaveChanges();
            ResponseModel res = new ResponseModel("Transactions success", null, "404");

            return(res);
        }
        public ResponseModel PutBill([FromRoute] int id, [FromBody] Bill bill)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel res = new ResponseModel("Update fail", null, "404");
                return(res);
            }
            float    amount     = bill.Amount_Bill;
            string   disciption = bill.Desciption;
            DateTime date_e     = bill.date_e;
            DateTime date_s     = bill.date_s;
            bool     isEdit     = bill.isEdit;
            string   id_time    = bill.id_Time;

            bill             = _context.Bill.Where(m => m.Id_Bill == id).FirstOrDefault();
            bill.Amount_Bill = amount;
            bill.Desciption  = disciption;
            bill.date_e      = date_e;
            bill.date_s      = date_s;
            bill.isEdit      = isEdit;
            bill.id_Time     = id_time;
            try
            {
                if (bill.isEdit == false)
                {
                    bill.isPay = true;
                }
                _context.Bill.Update(bill);
                _context.Entry(bill).State = EntityState.Modified;
                _context.SaveChanges();
                ResponseModel res = new ResponseModel("Update success", null, "404");
                return(res);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BillExists(id))
                {
                    ResponseModel res = new ResponseModel("Not found", null, "404");
                    return(res);
                }
                else
                {
                    throw;
                }
            }
        }
Example #11
0
        public ResponseModel PutTrip([FromRoute] string id, [FromBody] Trip trip)
        {
            string name = trip.Name_Trip;

            trip = _context.Trips.Where(m => m.Id_Trip.ToString() == id).FirstOrDefault();
            if (trip == null)
            {
                ResponseModel res1 = new ResponseModel("Update fail", null, "404");
                return(res1);
            }
            trip.Name_Trip = name;
            _context.Trips.Update(trip);
            _context.SaveChanges();
            ResponseModel res = new ResponseModel("Update successs", null, "404");

            return(res);
        }
        public ResponseModel PutBank([FromRoute] string id, [FromBody] Bank bank)
        {
            string name     = bank.Name_Bank;
            float  interest = bank.Interest;

            bank = _context.Bank.Where(m => m.Id_Bank.ToString() == id).FirstOrDefault();
            if (bank == null)
            {
                ResponseModel res1 = new ResponseModel("Update fail", null, "404");
                return(res1);
            }
            bank.Name_Bank = name;
            bank.Interest  = interest;
            _context.Bank.Update(bank);
            _context.SaveChanges();
            ResponseModel res = new ResponseModel("Update successs", null, "404");

            return(res);
        }
        public ResponseModel GetgetBill([FromQuery] string id)
        {
            var bills = _context.Bill.Where(w => w.Id_Wallet == id);
            var list  = new ArrayList();

            foreach (Bill bill1 in bills)
            {
                if (bill1.date_e <= DateTime.Today)
                {
                    bill1.isFinnish = true;
                    _context.Bill.Update(bill1);
                }
            }
            _context.SaveChanges();
            var bill = _context.Bill
                       .Where(w => w.Id_Wallet == id);

            foreach (Bill bill2 in bill)
            {
                if (bill2.Id_Category == null)
                {
                    var log = from a in _context.Bill
                              join c in _context.TypeCategories
                              on a.Id_Type equals c.Id_type.ToString()
                              join d in _context.Time_Periodic
                              on a.id_Time equals d.id_Time.ToString()
                                  where (a.Id_Category == null && a.Id_Bill == bill2.Id_Bill)
                              select new
                    {
                        idwallet    = a.Id_Wallet,
                        idBill      = a.Id_Bill,
                        name        = c.Name_Type,
                        image       = c.Image_Type,
                        amount      = a.Amount_Bill,
                        date_s      = a.date_s,
                        date_e      = a.date_e,
                        isPay       = a.isPay,
                        isFinnish   = a.date_e >= DateTime.Now ? false : true,
                        time        = d.desciption,
                        date_time_s = a.date_s,
                        date_time_e =
                            (a.id_Time == "1" ? a.date_s.AddDays(1) :
                             a.id_Time == "2" ? a.date_s.AddDays(7) :
                             a.id_Time == "3" ? DateTime.Today.AddDays(DateTime.DaysInMonth(2020, DateTime.Today.Month) - DateTime.Today.Day) :
                             DateTime.Today.AddDays(365 - (a.date_s.DayOfYear - 1)))
                    };
                    var get = log.Where(m => m.idwallet.Equals(id)).AsEnumerable();
                    foreach (object l in get)
                    {
                        list.Add(l);
                    }
                }
                if (bill2.Id_Type == null)
                {
                    var log = from a in _context.Bill
                              join b in _context.Categories
                              on a.Id_Category equals b.Id_Cate.ToString()
                              join d in _context.Time_Periodic
                              on a.id_Time equals d.id_Time.ToString()
                                  where (a.Id_Type == null && a.Id_Bill == bill2.Id_Bill)
                              select new
                    {
                        idwallet    = a.Id_Wallet,
                        idBill      = a.Id_Bill,
                        name        = b.NameCate,
                        image       = b.ImageCate,
                        amount      = a.Amount_Bill,
                        date_s      = a.date_s,
                        date_e      = a.date_e,
                        isPay       = a.isPay,
                        isFinnish   = a.date_e >= DateTime.Now ? false : true,
                        time        = d.desciption,
                        date_time_s = a.date_s,
                        date_time_e =
                            (a.id_Time == "1" ? a.date_s.AddDays(1) :
                             a.id_Time == "2" ? a.date_s.AddDays(7) :
                             a.id_Time == "3" ? DateTime.Today.AddDays(DateTime.DaysInMonth(2020, DateTime.Today.Month) - DateTime.Today.Day) :
                             DateTime.Today.AddDays(365 - (a.date_s.DayOfYear - 1)))
                    };
                    var get = log.Where(m => m.idwallet.Equals(id)).AsEnumerable();

                    foreach (object l in get)
                    {
                        list.Add(l);
                    }
                }
                //ResponseModel res = new ResponseModel("Bill", list, "200");
                //return res;
            }
            ResponseModel res1 = new ResponseModel("Budget", list, "200");

            return(res1);
        }
        public ResponseModel GetgetPeriodic([FromQuery] string id)
        {
            var    list   = new ArrayList();
            Wallet wallet = _context.Wallets.Where(m => m.Id_Wallet.ToString() == id).FirstOrDefault();
            var    per    = _context.Periodic.Where(w => w.Id_Wallet == id.ToString());

            foreach (Periodic periodic1 in per)
            {
                //thanh toán định kì theo ngày
                if (periodic1.id_Time == "1" && periodic1.date_s.AddDays(1) == DateTime.Today)
                {
                    Income_Outcome income = new Income_Outcome();
                    income.Amount           = periodic1.Amount_Per;
                    income.Description_come = "Thanh toán định kì";
                    income.Date_come        = DateTime.Today.ToString();
                    income.Id_Per           = periodic1.Id_Per.ToString();
                    income.WalletId_Wallet  = periodic1.Id_Wallet;
                    wallet.Amount_now       = wallet.Amount_now - periodic1.Amount_Per;
                    _context.Income_Outcomes.Add(income);
                }
                //thanh toán định kì theo tuần
                if (periodic1.id_Time == "2" && periodic1.date_s.AddDays(7) == DateTime.Today)
                {
                    Income_Outcome income = new Income_Outcome();
                    income.Amount           = periodic1.Amount_Per;
                    income.Description_come = "Thanh toán định kì";
                    income.Date_come        = DateTime.Today.ToString();
                    income.Id_Per           = periodic1.Id_Per.ToString();
                    income.WalletId_Wallet  = periodic1.Id_Wallet;
                    income.Is_Come          = false;
                    wallet.Amount_now       = wallet.Amount_now - periodic1.Amount_Per;
                    _context.Income_Outcomes.Add(income);
                }
                //thanh toán định kì theo tháng
                if (periodic1.id_Time == "2" &&
                    periodic1.date_s.AddDays(DateTime.DaysInMonth(periodic1.date_s.Year, periodic1.date_s.Month)) == DateTime.Today)
                {
                    Income_Outcome income = new Income_Outcome();
                    income.Amount           = periodic1.Amount_Per;
                    income.Description_come = "Thanh toán định kì";
                    income.Date_come        = DateTime.Today.ToString();
                    income.Id_Per           = periodic1.Id_Per.ToString();
                    income.WalletId_Wallet  = periodic1.Id_Wallet;
                    income.Is_Come          = false;
                    wallet.Amount_now       = wallet.Amount_now - periodic1.Amount_Per;
                    _context.Income_Outcomes.Add(income);
                }
                //thanh toán định kì theo tháng
                if (periodic1.id_Time == "2" && periodic1.date_s.AddDays(365) == DateTime.Today)
                {
                    Income_Outcome income = new Income_Outcome();
                    income.Amount           = periodic1.Amount_Per;
                    income.Description_come = "Thanh toán định kì";
                    income.Date_come        = DateTime.Today.ToString();
                    income.Id_Per           = periodic1.Id_Per.ToString();
                    income.WalletId_Wallet  = periodic1.Id_Wallet;
                    income.Is_Come          = false;
                    wallet.Amount_now       = wallet.Amount_now - periodic1.Amount_Per;
                    _context.Income_Outcomes.Add(income);
                }
                if (periodic1.date_e <= DateTime.Today)
                {
                    periodic1.isFinnish = true;
                    _context.Periodic.Update(periodic1);
                }
            }
            _context.Wallets.Update(wallet);
            _context.SaveChanges();

            var per1 = _context.Periodic
                       .Where(w => w.Id_Wallet == id);

            foreach (Periodic periodic in per1)
            {
                if (periodic.Id_Cate == null)
                {
                    var log = from a in _context.Periodic
                              join c in _context.TypeCategories
                              on a.Id_Type equals c.Id_type.ToString()
                              join d in _context.Time_Periodic
                              on a.id_Time equals d.id_Time.ToString()
                                  where (a.Id_Cate == null && a.Id_Per == periodic.Id_Per)
                              select new
                    {
                        idwallet    = a.Id_Wallet,
                        idPeriodic  = a.Id_Per,
                        name        = c.Name_Type,
                        image       = c.Image_Type,
                        amount      = a.Amount_Per,
                        date_s      = a.date_s,
                        date_e      = a.date_e,
                        time        = d.desciption,
                        is_Finish   = a.date_e >= DateTime.Now ? false : true,
                        date_time_s = a.date_s,
                        date_time_e =
                            (a.id_Time == "1" ? a.date_s.AddDays(1) :
                             a.id_Time == "2" ? a.date_s.AddDays(7) :
                             a.id_Time == "3" ? DateTime.Today.AddDays(DateTime.DaysInMonth(2020, DateTime.Today.Month) - DateTime.Today.Day) :
                             DateTime.Today.AddDays(365 - (a.date_s.DayOfYear - 1)))
                    };
                    var get = log.Where(m => m.idwallet.Equals(id)).AsEnumerable();

                    foreach (object l in get)
                    {
                        list.Add(l);
                    }
                }
                if (periodic.Id_Type == null)
                {
                    var log = from a in _context.Periodic
                              join b in _context.Categories
                              on a.Id_Cate equals b.Id_Cate.ToString()
                              join d in _context.Time_Periodic
                              on a.id_Time equals d.id_Time.ToString()
                                  where (a.Id_Type == null && a.Id_Per == periodic.Id_Per)
                              select new
                    {
                        idwallet    = a.Id_Wallet,
                        idPeriodic  = a.Id_Per,
                        name        = b.NameCate,
                        image       = b.ImageCate,
                        amount      = a.Amount_Per,
                        date_s      = a.date_s,
                        date_e      = a.date_e,
                        time        = d.desciption,
                        is_Finish   = a.date_e >= DateTime.Now ? false : true,
                        date_time_s = a.date_s,
                        date_time_e =
                            (a.id_Time == "1" ? a.date_s.AddDays(1) :
                             a.id_Time == "2" ? a.date_s.AddDays(7) :
                             a.id_Time == "3" ? DateTime.Today.AddDays(DateTime.DaysInMonth(2020, DateTime.Today.Month) - DateTime.Today.Day) :
                             DateTime.Today.AddDays(365 - (a.date_s.DayOfYear - 1)))
                    };
                    var get = log.Where(m => m.idwallet.Equals(id)).AsEnumerable();

                    foreach (object l in get)
                    {
                        list.Add(l);
                    }
                }
            }
            ResponseModel res1 = new ResponseModel("Periodic", list, "404");

            return(res1);
        }
Example #15
0
        public ResponseModel PostTransfers([FromBody] Transfers transfers)
        {
            int    id_chuyen     = transfers.id_chuyen;
            int    id_nhan       = transfers.id_nhan;
            float  amount        = transfers.amount;
            string dis           = transfers.desciption;
            Wallet wallet_chuyen = _context.Wallets.Where(x => x.Id_Wallet == id_chuyen).FirstOrDefault();
            Wallet wallet_nhan   = _context.Wallets.Where(x => x.Id_Wallet == id_nhan).FirstOrDefault();

            try
            {
                if (wallet_chuyen != null && wallet_nhan != null)
                {
                    wallet_chuyen.Amount_now = wallet_chuyen.Amount_now - amount;
                    wallet_nhan.Amount_now   = wallet_nhan.Amount_now + amount;
                    if (transfers.desciption == "")
                    {
                        transfers.desciption = "Chuyển khoản";
                    }
                    transfers.date = DateTime.Today;
                    Income_Outcome income_chuyen = new Income_Outcome();
                    Income_Outcome income_nhan   = new Income_Outcome();
                    income_chuyen.Amount    = amount;
                    income_chuyen.Date_come = DateTime.Today.ToString();
                    if (transfers.desciption == "")
                    {
                        income_chuyen.Description_come = "Chuyển khoản ";
                    }
                    else
                    {
                        income_chuyen.Description_come = transfers.desciption;
                    }

                    income_chuyen.WalletId_Wallet = id_chuyen.ToString();
                    income_chuyen.Is_Come         = false;
                    income_chuyen.Id_type         = "16";
                    income_chuyen.CategoryId_Cate = null;
                    income_chuyen.LoanId_Loan     = null;
                    income_chuyen.TripId_Trip     = null;
                    _context.Income_Outcomes.Add(income_chuyen);

                    income_nhan.Amount           = amount;
                    income_nhan.Date_come        = DateTime.Today.ToString();
                    income_nhan.Description_come = "Nhận chuyển khoản ";
                    income_nhan.WalletId_Wallet  = id_nhan.ToString();
                    income_nhan.Is_Come          = true;
                    income_nhan.Id_type          = "16";
                    income_nhan.CategoryId_Cate  = null;
                    income_nhan.LoanId_Loan      = null;
                    income_nhan.TripId_Trip      = null;
                    _context.Income_Outcomes.Add(income_nhan);

                    _context.Transfers.Add(transfers);
                    _context.Wallets.Update(wallet_chuyen);
                    _context.Wallets.Update(wallet_nhan);
                    _context.SaveChanges();
                    ResponseModel res = new ResponseModel("Transfers success", null, "200");
                    return(res);
                }
                else
                {
                    ResponseModel res = new ResponseModel("Transfers fail", null, "404");
                    return(res);
                }
            }
            catch
            {
                ResponseModel res = new ResponseModel("Transfers fail", null, "404");
                return(res);
            }
        }
        public ResponseModel GetgetBudget([FromQuery] string id)
        {
            var list   = new ArrayList();
            var budget = _context.Budget
                         .Where(w => w.Id_Wallet == id);

            foreach (Budget budget1 in budget)
            {
                if (budget1.time_e < DateTime.Today)
                {
                    budget1.isFinnish = true;
                    _context.Budget.Update(budget1);
                }
            }
            _context.SaveChanges();

            var budget_ = _context.Budget
                          .Where(w => w.Id_Wallet == id);

            foreach (Budget budget1 in budget_)
            {
                if (budget1.Id_Cate == null)
                {
                    var log = from a in _context.Budget
                              join c in _context.TypeCategories
                              on a.Id_type equals c.Id_type.ToString()
                              //join d in _context.Time_Periodic
                              //on a.id_Time equals d.id_Time.ToString()
                                  where (a.Id_Cate == null && a.Id_Budget == budget1.Id_Budget)
                              select new
                    {
                        idwallet    = a.Id_Wallet,
                        idBudget    = a.Id_Budget,
                        name        = c.Name_Type,
                        image       = c.Image_Type,
                        amount      = a.Amount_Budget,
                        remain      = a.Remain,
                        time_s      = a.time_s,
                        time_e      = a.time_e,
                        time_remain = (a.time_e - DateTime.Now),
                        check       = a.time_e < DateTime.Now ? true : false,
                        date_time_s = a.time_s,
                        date_time_e = a.time_e
                                      //(a.id_Time == "1" ? a.time_s.AddDays(1) :
                                      //a.id_Time == "2" ? a.time_s.AddDays(7) :
                                      //a.id_Time == "3" ? DateTime.Today.AddDays(DateTime.DaysInMonth(2020, DateTime.Today.Month) - DateTime.Today.Day) :
                                      //DateTime.Today.AddDays(365 - (a.time_s.DayOfYear - 1)))
                    };
                    var get = log.Where(m => m.idwallet.Equals(id)).AsEnumerable();
                    foreach (object l in get)
                    {
                        list.Add(l);
                    }
                }
                if (budget1.Id_type == null)
                {
                    var log = from a in _context.Budget
                              join b in _context.Categories
                              on a.Id_Cate equals b.Id_Cate.ToString()
                              //join d in _context.Time_Periodic
                              //on a.id_Time equals d.id_Time.ToString()
                                  where (a.Id_type == null && a.Id_Budget == budget1.Id_Budget)
                              select new
                    {
                        idwallet    = a.Id_Wallet,
                        idBudget    = a.Id_Budget,
                        name        = b.NameCate,
                        image       = b.ImageCate,
                        amount      = a.Amount_Budget,
                        remain      = a.Remain,
                        time_s      = a.time_s,
                        time_e      = a.time_e,
                        time_remain = (a.time_e - DateTime.Now),
                        check       = a.time_e < DateTime.Now ? true : false,
                        date_time_s = a.time_s,
                        date_time_e = a.time_e
                                      //(a.id_Time == "1" ? a.time_s.AddDays(1) :
                                      //a.id_Time == "2" ? a.time_s.AddDays(7) :
                                      //a.id_Time == "3" ? DateTime.Today.AddDays(DateTime.DaysInMonth(2020, DateTime.Today.Month) - DateTime.Today.Day) :
                                      //DateTime.Today.AddDays(365 - (a.time_s.DayOfYear - 1)))
                    };
                    var get = log.Where(m => m.idwallet.Equals(id)).AsEnumerable();
                    foreach (object l in get)
                    {
                        list.Add(l);
                    }
                }
            }
            ResponseModel res1 = new ResponseModel("Budget", list, "200");

            return(res1);
        }