public async Task <ActionResult> DeleteConfirmed(int id) { Expense_Invoice expense_Invoice = await db.Expense_Invoices.FindAsync(id); db.Expense_Invoices.Remove(expense_Invoice); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteExpInvConfirmed(int Expense_InvoiceId) { Expense_Invoice Expense_Invoice = await UOW.Expense_InvoiceRepository.GetExpense_Invoice(Expense_InvoiceId); int InvoiceId = Expense_Invoice.InvoiceId; Expense_Invoice expense_Invoice = await UOW.Expense_InvoiceRepository.DeleteExpense_Invoice(Expense_InvoiceId); return(RedirectToAction("ListExpInv", new { InvoiceId = InvoiceId })); }
// GET: Expense_Invoices/Delete/5 public async Task <ActionResult> DeleteExpInv(int Expense_InvoiceId) { if (Expense_InvoiceId == 0) { return(HttpNotFound()); } Expense_Invoice expense_Invoice = await UOW.Expense_InvoiceRepository.GetExpense_Invoice(Expense_InvoiceId); return(View(expense_Invoice)); }
public ActionResult CreateExpInv([Bind(Include = "Expense_InvoiceId,InvoiceId,OverexposureContractId,ExpenseId,Quantity,SumExpense")] Expense_Invoice expense_Invoice, int InvoiceId) { if (expense_Invoice.Quantity < 0) { ModelState.AddModelError("Quantity", "Некорректное количество"); } UOW.Expense_InvoiceRepository.SaveExpense_Invoice(expense_Invoice); ViewBag.ExpenseId = new SelectList(UOW.ExpenseRepository.AllExpenses, "ExpenseId", "TypeOfExpense", expense_Invoice.ExpenseId); ViewBag.InvoiceId = InvoiceId; return(RedirectToAction("ListExpInv", new { InvoiceId = expense_Invoice.InvoiceId })); }
public void SaveExpense_Invoice(Expense_Invoice Expense_Invoice) { if (Expense_Invoice.Expense_InvoiceId == 0) { Invoice invoice = _context.Invoices.Find(Expense_Invoice.InvoiceId); if (invoice == null) { invoice = new Invoice(); invoice.DateOfInvoice = DateTime.Now; invoice.OverexposureContractId = Expense_Invoice.OverexposureContractId; _context.Invoices.Add(invoice); } var exp_inv = _context.Expense_Invoices.Where(e => e.InvoiceId == Expense_Invoice.InvoiceId); double cost = _context.Expenses.Find(Expense_Invoice.ExpenseId).CostOfExpense; bool flag = false; foreach (Expense_Invoice ei in exp_inv) { if (ei.ExpenseId == Expense_Invoice.ExpenseId) { ei.Quantity = ei.Quantity + Expense_Invoice.Quantity; ei.SumExpense = ei.SumExpense + Expense_Invoice.Quantity * cost; invoice.SumOfInvoice = invoice.SumOfInvoice + Expense_Invoice.Quantity * cost; flag = true; } } if (flag == false) { Expense_Invoice.InvoiceId = invoice.InvoiceId; Expense_Invoice.SumExpense = Expense_Invoice.Quantity * _context.Expenses.Find(Expense_Invoice.ExpenseId).CostOfExpense; _Expense_Invoices.Add(Expense_Invoice); invoice.SumOfInvoice += Expense_Invoice.SumExpense; } _context.SaveChanges(); } else { _context.Entry(Expense_Invoice).State = EntityState.Modified; double cost = _context.Expenses.Find(Expense_Invoice.ExpenseId).CostOfExpense; Invoice invoice = _context.Invoices.Find(Expense_Invoice.InvoiceId); Expense_Invoice.SumExpense = Expense_Invoice.Quantity * cost; var ExpInvs = _Expense_Invoices.Where(e => e.InvoiceId == Expense_Invoice.InvoiceId); invoice.SumOfInvoice = 0; foreach (Expense_Invoice ei in ExpInvs) { if (ei.SumExpense != 0) { invoice.SumOfInvoice += ei.SumExpense; } } _context.SaveChanges(); } }
// GET: Expense_Invoices/Edit/5 public async Task <ActionResult> EditExpInv(int Expense_InvoiceId) { Expense_Invoice expense_Invoice = await UOW.Expense_InvoiceRepository.GetExpense_Invoice(Expense_InvoiceId); if (expense_Invoice == null) { return(HttpNotFound()); } ViewBag.ExpenseId = new SelectList(UOW.ExpenseRepository.AllExpenses, "ExpenseId", "TypeOfExpense", expense_Invoice.ExpenseId); ViewBag.InvoiceId = expense_Invoice.InvoiceId; return(View(expense_Invoice)); }
public async Task <ActionResult> Edit([Bind(Include = "Expense_InvoiceId,InvoiceId,OverexposureContractId,ExpenseId,Quantity,SumExpense")] Expense_Invoice expense_Invoice) { if (ModelState.IsValid) { db.Entry(expense_Invoice).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ExpenseId = new SelectList(db.Expenses, "ExpenseId", "TypeOfExpense", expense_Invoice.ExpenseId); ViewBag.InvoiceId = new SelectList(db.Invoices, "InvoiceId", "InvoiceId", expense_Invoice.InvoiceId); return(View(expense_Invoice)); }
// GET: Expense_Invoices/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Expense_Invoice expense_Invoice = await db.Expense_Invoices.FindAsync(id); if (expense_Invoice == null) { return(HttpNotFound()); } return(View(expense_Invoice)); }
public bool Update(Expense_Invoice expense_Invoice) { try { var updateEntity = _expenseInvoiceRepo.Find(expense_Invoice.Id); AutoMapper.Mapper.DynamicMap(expense_Invoice, updateEntity); _expenseInvoiceRepo.Update(updateEntity); _uow.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool Insert(Expense_Invoice expense_Invoice) { try { var newEntity = AutoMapper.Mapper.DynamicMap <Expense_Invoice>(expense_Invoice); newEntity.Status = Status.Active; _expenseInvoiceRepo.Insert(newEntity); _uow.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public async Task <Expense_Invoice> DeleteExpense_Invoice(int Expense_InvoiceId) { Expense_Invoice expense_Invoice = await _Expense_Invoices.FindAsync(Expense_InvoiceId); if (expense_Invoice != null) { int InvoiceId = expense_Invoice.InvoiceId; Invoice invoice = _context.Invoices.Find(expense_Invoice.InvoiceId); invoice.SumOfInvoice = invoice.SumOfInvoice - expense_Invoice.SumExpense; _Expense_Invoices.Remove(expense_Invoice); await _context.SaveChangesAsync(); } return(expense_Invoice); }
// GET: Expense_Invoices/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Expense_Invoice expense_Invoice = await db.Expense_Invoices.FindAsync(id); if (expense_Invoice == null) { return(HttpNotFound()); } ViewBag.ExpenseId = new SelectList(db.Expenses, "ExpenseId", "TypeOfExpense", expense_Invoice.ExpenseId); ViewBag.InvoiceId = new SelectList(db.Invoices, "InvoiceId", "InvoiceId", expense_Invoice.InvoiceId); return(View(expense_Invoice)); }
private void BtnSave_Click(object sender, EventArgs e) { if (DailyCastingEntryType == 1) { #region Variables DateTime ExpenseDate = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now)); decimal Price = nudPrice.Value; string Descriptions = txtDesciptions.Text; #endregion #region Service UnitofWork unitofWork = new UnitofWork(ctx); Expense_Vehicle_Service expense_Vehicle_Service = new Expense_Vehicle_Service(unitofWork); TotalExpenses_Service totalExpenses_Service = new TotalExpenses_Service(unitofWork); #endregion if (Price > 0 && !string.IsNullOrEmpty(Descriptions)) { DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { Expense_Vehicle expense_Vehicle = new Expense_Vehicle() { ExpenseDate = ExpenseDate, Descriptions = Descriptions, Price = Price }; if (expense_Vehicle_Service.Insert(expense_Vehicle)) { TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Vehicle); if (totalExpenses != null) { totalExpenses.Price += Price; if (totalExpenses_Service.Update(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); txtDesciptions.Text = ""; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { totalExpenses = new TotalExpenses() { ExpenseDate = ExpenseDate, ExpenseType = ExpenseType.Vehicle, ExpenseTypeDesciptions = "Araç", Price = Price, Status = Status.Active, }; if (totalExpenses_Service.Insert(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); txtDesciptions.Text = ""; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (DailyCastingEntryType == 2) { #region Variables DateTime ExpenseDate = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now)); InvoiceType invoiceType = new InvoiceType(); switch (cmbInvoice.SelectedValue) { case "0": invoiceType = InvoiceType.That; break; case "1": invoiceType = InvoiceType.Electricity; break; case "2": invoiceType = InvoiceType.NaturalGas; break; case "3": invoiceType = InvoiceType.Internet; break; case "4": invoiceType = InvoiceType.Other; break; default: break; } string Descriptions = txtDesciptions.Text; decimal Price = nudPrice.Value; #endregion #region Service UnitofWork unitofWork = new UnitofWork(ctx); Expense_Invoice_Service expense_Invoice_Service = new Expense_Invoice_Service(unitofWork); TotalExpenses_Service totalExpenses_Service = new TotalExpenses_Service(unitofWork); #endregion if (Price > 0 && cmbInvoice.Text != "Fatura Tipi Seçiniz...") { DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { Expense_Invoice expense_Invoice = new Expense_Invoice() { ExpenseDate = ExpenseDate, InvoiceType = enumHelper.GetEnumDescription(invoiceType), Descriptions = Descriptions, Price = Price, Status = Status.Active }; if (expense_Invoice_Service.Insert(expense_Invoice)) { TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Invoice); if (totalExpenses != null) { totalExpenses.Price += Price; if (totalExpenses_Service.Update(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); cmbInvoice.SelectedIndex = 0; txtDesciptions.Text = ""; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { totalExpenses = new TotalExpenses() { ExpenseDate = ExpenseDate, ExpenseType = ExpenseType.Invoice, ExpenseTypeDesciptions = "Fatura", Price = Price, Status = Status.Active, }; if (totalExpenses_Service.Insert(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); cmbInvoice.SelectedIndex = 0; txtDesciptions.Text = ""; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (DailyCastingEntryType == 3) { #region Variables DateTime ExpenseDate = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now)); string SupplirsCode = cmbSuppliers.SelectedValue.ToString(); decimal Price = nudPrice.Value; string Descriptions = txtDesciptions.Text; #endregion #region Service UnitofWork unitofWork = new UnitofWork(ctx); SupplierCompanies_Service supplierCompanies_Service = new SupplierCompanies_Service(unitofWork); Expense_Suppliers_Service expense_Suppliers_Service = new Expense_Suppliers_Service(unitofWork); TotalExpenses_Service totalExpenses_Service = new TotalExpenses_Service(unitofWork); #endregion if (!string.IsNullOrEmpty(SupplirsCode) && Price > 0) { DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { SupplierCompanies supplierCompanies = supplierCompanies_Service.GetSupplierCompanies(SupplirsCode); Expense_Suppliers expense_Suppliers = new Expense_Suppliers() { Status = Status.Active, ExpenseDate = ExpenseDate, Price = Price, Descriptions = Descriptions, SupplierCode = supplierCompanies.Code, SupplierName = supplierCompanies.Name }; if (expense_Suppliers_Service.Insert(expense_Suppliers)) { TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Suppliers); if (totalExpenses != null) { totalExpenses.Price += Price; if (totalExpenses_Service.Update(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); cmbSuppliers.SelectedIndex = 0; txtDesciptions.Text = ""; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { totalExpenses = new TotalExpenses() { ExpenseDate = ExpenseDate, ExpenseType = ExpenseType.Suppliers, ExpenseTypeDesciptions = "Tedarikçi", Price = Price, Status = Status.Active, }; if (totalExpenses_Service.Insert(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); cmbSuppliers.SelectedIndex = 0; txtDesciptions.Text = ""; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (DailyCastingEntryType == 4) { #region Variables DateTime ExpenseDate = Convert.ToDateTime(string.Format("{0: dd/MM/yyyy 00:00:00}", DateTime.Now)); string FullName = cmbStaffs.Text; string StaffExpenseType = cmbStaffExpense.Text; decimal Price = nudPrice.Value; #endregion #region Service UnitofWork unitofWork = new UnitofWork(ctx); Staff_Service staff_Service = new Staff_Service(unitofWork); Expense_Staff_Service expense_Staff_Service = new Expense_Staff_Service(unitofWork); TotalExpenses_Service totalExpenses_Service = new TotalExpenses_Service(unitofWork); #endregion if (!string.IsNullOrEmpty(FullName) && !string.IsNullOrEmpty(StaffExpenseType) && Price > 0) { DialogResult dialogResult = MessageBox.Show("Kaydı Eklemek İstediğinize Emin misiniz?", "Yeni Kayıt", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { Expense_Staff expense_Staff = new Expense_Staff() { ExpenseDate = ExpenseDate, FullName = FullName, Price = Price, StaffExpenseType = StaffExpenseType, Status = Status.Active }; if (expense_Staff_Service.Insert(expense_Staff)) { TotalExpenses totalExpenses = totalExpenses_Service.GetTotalExpenses(ExpenseDate, ExpenseType.Staff); if (totalExpenses != null) { totalExpenses.Price += Price; if (totalExpenses_Service.Update(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); cmbStaffs.SelectedIndex = 0; cmbStaffExpense.SelectedIndex = 0; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { totalExpenses = new TotalExpenses() { ExpenseDate = ExpenseDate, ExpenseType = ExpenseType.Staff, ExpenseTypeDesciptions = "Personel", Price = Price, Status = Status.Active, }; if (totalExpenses_Service.Insert(totalExpenses)) { MessageBox.Show("İşlem Başarılı."); cmbStaffs.SelectedIndex = 0; cmbStaffExpense.SelectedIndex = 0; nudPrice.Value = 0; } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("İşlem Başarısız.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Boş Geçilemez.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }