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; } } }
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; } } }
public ResponseModel PostIncome_Outcome([FromBody] Income_Outcome income_Outcome) { Income_Outcome income = new Income_Outcome(); 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.Amount = amount; income.Date_come = date; income.Description_come = desciption; income.Is_Come = false; income.CategoryId_Cate = id_cate; income.LoanId_Loan = id_loan; income.TripId_Trip = id_trip; income.WalletId_Wallet = id_wallet; income.Id_Bill = id_bill; income.Id_Budget = id_budget; income.Id_Per = id_per; income.Id_type = id_type; Wallet wallet = _context.Wallets.Where(m => m.Id_Wallet.ToString() == id_wallet).FirstOrDefault(); if (wallet.Id_Type_Wallet != "1" && amount > wallet.Amount_now && income_Outcome.Id_type != "12" && income_Outcome.Id_type != "13" && income_Outcome.Id_type != "14" && income_Outcome.Id_type != "15" && income_Outcome.Id_type != "16" && income_Outcome.Id_type != "18") { ResponseModel res = new ResponseModel("Ví tiền hiện tại của bạn không đủ thực hiện thao tác này", null, "404"); return(res); } try { if (income.Date_come == null) { income.Date_come = DateTime.Today.ToString(); } if (id_budget != null) { Budget budget = _context.Budget.Where(m => m.Id_Budget.ToString() == id_budget).FirstOrDefault(); if (budget.time_s.Ticks <= DateTime.Parse(income.Date_come).Ticks&& budget.time_e.Ticks >= DateTime.Parse(income.Date_come).Ticks) { if (id_type != "12" || id_type != "13" || id_type != "14" || id_type != "15" || id_type != "16" || id_type != "18") { budget.Remain = budget.Remain + amount; } else { budget.Remain = budget.Remain - amount; } _context.Budget.Update(budget); } } if (id_bill != null) { income.Is_Come = false; Bill bill = _context.Bill.Where(m => m.Id_Bill.ToString() == id_bill).FirstOrDefault(); if (bill.date_s.Ticks == DateTime.Today.Ticks) { if (bill.id_Time == "1") { if (DateTime.Now.AddDays(1).Ticks > bill.date_e.Ticks) { bill.isPay = true; } else { bill.isPay = false; bill.date_s = bill.date_s.AddDays(1); } } if (bill.id_Time == "2") { if (DateTime.Now.AddDays(7).Ticks > bill.date_e.Ticks) { bill.isPay = true; } else { bill.isPay = false; bill.date_s = bill.date_s.AddDays(7); } } if (bill.id_Time == "3") { if (DateTime.Now.AddDays(getDayOfMonth()).Ticks > bill.date_e.Ticks) { bill.isPay = true; } else { bill.isPay = false; int month = DateTime.Now.Month; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: bill.date_s = bill.date_s.AddDays(31); break; case 2: int year = DateTime.Now.Year; if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { bill.date_s = bill.date_s.AddDays(29); } else { bill.date_s = bill.date_s.AddDays(28); } break; case 4: case 6: case 9: case 11: bill.date_s = bill.date_s.AddDays(30); break; } } } if (bill.id_Time == "4") { if (DateTime.Now.AddYears(1).Ticks > bill.date_e.Ticks) { bill.isPay = true; } else { bill.isPay = false; bill.date_s = bill.date_s.AddYears(1); } } income.Description_come = "Thanh toán hóa đơn"; income.Date_come = DateTime.Today.ToString(); income.CategoryId_Cate = bill.Id_Category; income.Id_type = bill.Id_Type; wallet.Amount_now = wallet.Amount_now - bill.Amount_Bill; income.Amount = bill.Amount_Bill; _context.Bill.Update(bill); } else { ResponseModel result = new ResponseModel("Chưa tới hạn thanh toán", null, "404"); return(result); } } if (id_type == "12" || id_type == "13" || id_type == "14" || id_type == "15" || id_type == "16" || id_type == "18") { income.Is_Come = true; wallet.Amount_now = wallet.Amount_now + amount; } else { wallet.Amount_now = wallet.Amount_now - amount; } _context.Wallets.Update(wallet); _context.Income_Outcomes.Add(income); _context.SaveChanges(); ResponseModel res = new ResponseModel("Create success", null, "200"); return(res); } catch { ResponseModel res = new ResponseModel("Create fail", null, "404"); return(res); } }
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); }
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); } }