public ActionResult Edit(int?id, bool?saved) { var items = GetAllItems(); var item = items.FirstOrDefault(x => x.Id == id.Value); int catId = item.IncomeTypeId; var cats = GetAllCategories(); var categories = cats.ToList(); categories.Insert(0, new CategoryModel { Name = "-- Please Select--", Id = 0 }); IEnumerable <SelectListItem> selectList = from c in categories select new SelectListItem { Selected = (c.Id == catId), Text = c.Name, Value = c.Id.ToString() }; IncomeModel cm = item; cm.selectList = selectList; cm.Saved = saved; return(View("Create", cm)); }
//[OutputCache(Duration = 3600, VaryByParam = "none")] public ActionResult Create() { int catId = 0; var cats = GetAllCategories(); var categories = cats.ToList(); categories.Insert(0, new CategoryModel { Name = "-- Please Select--", Id = 0 }); IEnumerable <SelectListItem> selectList = from c in categories select new SelectListItem { Selected = (c.Id == catId), Text = c.Name, Value = c.Id.ToString() }; IncomeModel cm = new IncomeModel { Id = 0, selectList = selectList }; return(View(cm)); }
public ActionResult Entry(IncomeViewModel income) { IncomeModel data = new IncomeModel(); #region Income Model data maping data.Amount = income.Amount; data.BankId = income.BankId; data.Date = income.Date; data.Particular = income.Particular; data.ChequeNo = income.ChequeNo; if (income.isCash == 1) { data.Cash = true; } else { data.Cheque = true; } #endregion bool isSaved = IncomeManager.SaveIncome(data); if (isSaved) { ViewBag.Message = "Income Saved"; } ViewBag.BankList = BankManager.LoadBank(); return(View()); }
public bool SaveBook(IncomeModel model, bool isIncome = false) { try { if (model.IncomeBook.ImageTempId != null) { model.IncomeBook.Cover = GetFileContent(model.IncomeBook.ImageTempId); } foreach (var author in model.IncomeAuthors) { if (author.ImageTempId != null) { author.Photo = GetFileContent(author.ImageTempId); } } var xmlString = SerializeModel(model); if (User.IsInRole("ADMIN") && isIncome && model.Id != null) { DataService.UpdateIncomeItem((Guid)model.Id, model.IncomeBook.Name, xmlString); } else { var id = DataService.ApplyIncomeItem(ItemTypeEnum.Book, (Guid)User.UserId, model.IncomeBook.Name, xmlString, model.Id); _mailService.NewIncome(id); } return(true); } catch (Exception ex) { // todo } return(false); }
private int UpdateItem(IncomeModel cm) { int id = 0; using (SqlConnection myConnection = new SqlConnection(GetConnectionString())) { using (SqlCommand cmd = new SqlCommand("IncomeUpdate", myConnection)) { cmd.CommandType = CommandType.StoredProcedure; myConnection.Open(); //SqlParameter custId = cmd.Parameters.AddWithValue("@CustomerId", 10); cmd.Parameters.AddWithValue("@Id", cm.Id); cmd.Parameters.AddWithValue("@IsActive", cm.IsActive); cmd.Parameters.AddWithValue("@Amount", cm.Amount); cmd.Parameters.AddWithValue("@Description", cm.Description); cmd.Parameters.AddWithValue("@StaffId", cm.StaffId); cmd.Parameters.AddWithValue("@IncomeTypeId", cm.IncomeTypeId); try { int.TryParse(cmd.ExecuteScalar().ToString(), out id); } catch { } } } return(id); }
//[OutputCache(Duration = 3600, VaryByParam = "id")] public ActionResult Delete(int?id) { var cats = GetAllItems(); IncomeModel cm = cats.FirstOrDefault(x => x.Id == id.Value); return(View(cm)); }
private double FinancialState(int t, IncomeModel incomeModel) { var allFundings = incomeModel.U + Inc.Take(t).Sum() * 0.8; var allSpendings = t / 3 * new Random().NextDouble() * incomeModel.MinThreshold; return(allFundings - allSpendings); }
public async Task IncomeService_Updates_Wallet_Updated_Income_Increase() { DateTime now = DateTime.UtcNow; UserModel user = new UserModel("Test User", new DateTime(), "*****@*****.**", "password", api.Enums.Currency.Euro); user._id = "1234567891234567891234"; user.Role = "user"; WalletModel wallet = new WalletModel("Unit Test", 0, true, 100, null, api.Enums.WalletColor.Green, now); wallet._id = "1234567891234567891234"; wallet.DateOffsetBalance = new List <DateOffsetBalance>(); wallet.DateOffsetBalance.Add(new DateOffsetBalance(DateTime.UtcNow, 100)); user.Wallets.Add(wallet); IncomeModel oldIncome = new IncomeModel(user._id, wallet._id, 100, DateTime.UtcNow, "unit test"); IncomeModel newIncome = new IncomeModel(user._id, wallet._id, 120, DateTime.UtcNow, "unit test"); IncomeService service = new IncomeService(); WalletModel newWallet = await service.UpdateWalletForUpdatedIncome(user, newIncome, oldIncome); newWallet.Balance.Should().Be(120); newWallet.LastUpdated.Should().NotBeOnOrBefore(now); newWallet.DateOffsetBalance.Should().NotBeNull(); }
public async Task <IActionResult> PutIncome(int id, IncomeModel income) { if (id != income.StatementId) { return(BadRequest()); } _context.Entry(income).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IncomeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void UpdateIncome(IncomeModel p) { Income ph = db.Incomes.GetItem(p.Income_PK); db.Incomes.Update(toIncome(ph, p)); db.Save(); }
public IActionResult Income() { ViewData["Message"] = "Add the moneys"; IncomeModel model = new IncomeModel(); model.Accounts = accountService.GetAccounts(); return(View(model)); }
public ActionResult Edit(IncomeModel cm, string[] orderNumbers) { int id = 0; var url = string.Empty; var extension = string.Empty; var imageName = string.Empty; if (ModelState.IsValid) { var username = User.Identity.Name.ToUpper(); var thisUser = _personService.GetAllForLogin().Where(x => x.Username.ToUpper().Equals(username)).FirstOrDefault(); cm.StaffId = thisUser.PersonID; if (cm.Id > 0) { cm.IsActive = true; id = UpdateItem(cm); } else { cm.IsActive = true; cm.IncomeDate = DateTime.Now; id = InsertItem(cm); } bool saved = true; return(RedirectToAction("Edit", new { id, saved })); } int catId = cm.IncomeTypeId; var cats = GetAllCategories(); var categories = cats.ToList(); categories.Insert(0, new CategoryModel { Name = "-- Please Select--", Id = 0 }); IEnumerable <SelectListItem> selectList = from c in categories select new SelectListItem { Selected = (c.Id == catId), Text = c.Name, Value = c.Id.ToString() }; cm.selectList = selectList; return(View(cm)); }
public async Task <bool> UpdateTraIncome([FromBody] string json) { IncomeModel income = new IncomeModel(this._context); var incomeObj = JsonSerializer.Deserialize <IncomeData>(json); // JSONからオブジェクトにデシリアライズ bool result = await income.UpdateTraIncome(incomeObj); return(result); }
public async Task <ActionResult> DeleteConfirmed(int id) { IncomeModel incomeModel = await db.IncomeModel.FindAsync(id); db.IncomeModel.Remove(incomeModel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private Income toIncome(Income p, IncomeModel i) { p.Date = i.Date; p.Income_PK = i.Income_PK; p.Login_FK = i.Login_FK; p.Source_of_the_income_FK = i.Source_of_the_income_FK; p.Sum = i.Sum; return(p); }
public void UpdateINCOME(IncomeModel inc) { INCOME i = db.INCOME.Find(inc.income_code_ID); i.id = inc.income_code_ID; i.income_guide_FK = (int)inc.income_guide_FK; i.income_size = (decimal)inc.income_size; i.income_date = (DateTime)inc.income_date; Save(); }
public async Task DeleteIncome(IncomeModel income) { var result = await _apiClient.DeleteAsync($"Incomes/{income.StatementId}"); if (result.IsSuccessStatusCode) { Incomes.Remove(income); } await OnDeleted(); }
public async Task <bool> CreateTraIncome(IncomeData json) { IncomeModel income = new IncomeModel(this._context); Console.WriteLine(json); //var incomeObj = JsonSerializer.Deserialize<IncomeData>(json); // JSONからオブジェクトにデシリアライズ //bool result = await income.InsertTraIncome(incomeObj); bool result = await income.InsertTraIncome(json); return(result); }
/// <summary> /// Save income /// </summary> /// <param name="model">Income model</param> /// <returns>ResponseStatusCodeHelper</returns> public ResponseStatusCodeHelper SaveIncome(IncomeModel model) { try { using (var _context = new TDHEntities()) { using (var trans = _context.Database.BeginTransaction()) { try { decimal _currentYearMonth = decimal.Parse(DateTime.Now.DateToString("yyyyMM")); MN_INCOME _md = new MN_INCOME(); _md.id = Guid.NewGuid(); _md.account_id = model.AccountID; _md.category_id = model.CategoryID; _md.title = model.Title; _md.date = model.Date; _md.purpose = model.Purpose; _md.notes = model.Notes; _md.money = model.Money; _md.create_by = model.CreateBy; _md.create_date = DateTime.Now; _context.MN_INCOME.Add(_md); _context.Entry(_md).State = EntityState.Added; _context.SaveChanges(); //MN_ACCOUNT. Update account income money MN_ACCOUNT _acc = _context.MN_ACCOUNT.FirstOrDefault(m => m.id == _md.account_id); _acc.input += model.Money; _context.MN_ACCOUNT.Attach(_acc); _context.Entry(_acc).State = EntityState.Modified; _context.SaveChanges(); trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw new ServiceException(FILE_NAME, "SaveIncome", model.CreateBy, ex); } } } } catch (ServiceException serviceEx) { throw serviceEx; } catch (Exception ex) { throw new ServiceException(FILE_NAME, "SaveIncome", model.CreateBy, ex); } Notifier.Notification(model.CreateBy, Message.InsertSuccess, Notifier.TYPE.Success); return(ResponseStatusCodeHelper.Success); }
public static IncomeModel checkIncome(Budynki budynek, DateTime?startDate, DateTime?endDate) { List <FakturyNapraw> expenseBills; List <Platnosci> incomeBills; double totalIncome = 0; double totalExpense = 0; using (var ctx = new DBProjectEntities()) { var residences = ctx.Mieszkania.Where(x => x.id_budynku == budynek.id) .Include(i => i.Usterki .Select(s => s.Naprawy .Select(ss => ss.FakturyNapraw))) .Include(i => i.Wynajmy.Select(s => s.Platnosci)); if (startDate == null && endDate == null) { foreach (var residence in residences) { incomeBills = residence.Wynajmy.SelectMany(s => s.Platnosci).ToList(); incomeBills.ForEach(x => totalIncome += x.cena); expenseBills = residence.Usterki.SelectMany(s => s.Naprawy.SelectMany(ss => ss.FakturyNapraw)).ToList(); expenseBills.ForEach(x => totalExpense += x.cena); } } else { foreach (var residence in residences) { incomeBills = residence.Wynajmy.SelectMany(s => s.Platnosci).Where(x => x.data_platnosci > startDate && x.data_platnosci < endDate).ToList(); incomeBills.ForEach(x => totalIncome += x.cena); expenseBills = residence.Usterki.SelectMany(s => s.Naprawy.SelectMany(ss => ss.FakturyNapraw).Where(x => x.data_platnosci > startDate && x.data_platnosci < endDate)).ToList(); expenseBills.ForEach(x => totalExpense += x.cena); } } } var buildingCosts = new IncomeModel { Id = idx, przychod = totalIncome, wydatek = totalExpense, profit = totalIncome - totalExpense, id_budynku = budynek.id, adres = budynek.adres_budynku }; idx++; return(buildingCosts); }
public static bool SaveIncome(IncomeModel data) { string sql = "Insert Into Income(Amount, Cash, Cheque, ChequeNo, BankId, Particular, Date)" + "Values(@Amount, @Cash, @Cheque, @ChequeNo, @BankId, @Particular, @Date)"; int rowAffected = SqlDataAccess.SaveData <IncomeModel>(sql, data); if (rowAffected > 0) { return(true); } return(false); }
// INCOME public void CreateINCOME(IncomeModel i) { db.INCOME.Add(new INCOME() { id = i.income_code_ID, income_user_FK = (int)i.income_user_FK, income_guide_FK = (int)i.income_guide_FK, income_date = (DateTime)i.income_date, income_size = (int)i.income_size }); Save(); }
private async Task <IncomeList> GetIncomeList(string id) { List <IncomeModel> dbRec = new List <IncomeModel>(); var record = await _context.Income.Where(a => a.UserId == id).SingleOrDefaultAsync(); //var incomeBayanihan = new IncomeModel //{ // IncomeType = "Bayanihan", // Description = "Bayanihan Income", // TotalAmount = record.BayanihanIncome, // NetIncome = record.NetIncome //}; var incomeBinary = new IncomeModel { IncomeType = "Incentives", Description = "Incentives Income", TotalAmount = record.DirectReferralIncome, NetIncome = record.NetIncome }; //var incomeUnilevel = new IncomeModel //{ // IncomeType = "Unilevel", // Description = "Unilevel Income", // TotalAmount = record.UnilevelIncome, // NetIncome = record.NetIncome //}; var incomeGeneology = new IncomeModel { IncomeType = "Pairing Bonus", Description = "Pairing Bonus Income", TotalAmount = record.GeneologyIncome, NetIncome = record.NetIncome }; //dbRec.Add(incomeBayanihan); dbRec.Add(incomeBinary); //dbRec.Add(incomeUnilevel); dbRec.Add(incomeGeneology); IncomeList incomeList = new IncomeList { Records = dbRec }; return(incomeList); }
// GET: Income/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IncomeModel incomeModel = await db.IncomeModel.FindAsync(id); if (incomeModel == null) { return(HttpNotFound()); } return(View(incomeModel)); }
public async Task <ActionResult> Edit([Bind(Include = "ID,reoccuring,daysTillReoccurance,name,amount,timeAdded")] IncomeModel incomeModel) { if (ModelState.IsValid) { PocketMoney pMoney = new PocketMoney(); incomeModel.MoveFunds(incomeModel.amount, incomeModel, pMoney); db.Entry(pMoney).State = EntityState.Modified; db.Entry(incomeModel).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(incomeModel)); }
public ActionResult Delete(IncomeModel cm) { int id = cm.Id; var cats = GetAllItems(); var cm1 = cats.FirstOrDefault(x => x.Id == id); cm1.IsActive = false; id = UpdateItem(cm1); return(RedirectToAction("Index")); }
public async Task <WalletModel> UpdateWalletForDeletedIncome(UserModel user, IncomeModel income) { WalletModel wallet = user.Wallets.Where(wallet => wallet._id == income.WalletId).First(); wallet.Balance -= income.Amount; wallet.LastUpdated = DateTime.UtcNow; try { wallet.DateOffsetBalance.Where(dateoffsetbalance => dateoffsetbalance.Date.Date == income.Date.Date).First().Balance -= income.Amount; } catch (Exception e) { } user.Wallets.Remove(user.Wallets.Where(a => a._id == wallet._id).First()); return(wallet); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } IncomeModel = await _context.IncomeModel.FirstOrDefaultAsync(m => m.Id == id); if (IncomeModel == null) { return(NotFound()); } return(Page()); }
public async Task <WalletModel> UpdateWalletForUpdatedIncome(UserModel user, IncomeModel newIncome, IncomeModel oldIncome) { double difference = newIncome.Amount - oldIncome.Amount; WalletModel wallet = user.Wallets.Where(wallet => wallet._id == oldIncome.WalletId).First(); wallet.Balance += difference; wallet.LastUpdated = DateTime.UtcNow; try { wallet.DateOffsetBalance.Where(dateoffsetbalance => dateoffsetbalance.Date.Date == oldIncome.Date.Date).First().Balance += difference; } catch (Exception e) { } user.Wallets.Remove(user.Wallets.Where(a => a._id == wallet._id).First()); return(wallet); }
public async Task <ActionResult <IncomeModel> > PostIncome(IncomeModel income) { income.UserId = _currentIdentity.GetUserId(); var category = _context.Categories.Include(c => c.Statements) .FirstOrDefault(c => c.Statements.Any(s => s.UserId.Equals(income.UserId)) && c.Name.Equals(income.Category.Name)); if (category != null) { income.Category = category; } _context.Incomes.Add(income); await _context.SaveChangesAsync(); return(CreatedAtAction("GetIncome", new { id = income.StatementId }, income)); }