public CommonResponseViewModel AddVendor(VendorViewModel vendorVM) { CommonResponseViewModel response = new CommonResponseViewModel(); var vendor = new EfDbContext.Vendor(); vendor.FirstName = vendorVM.firstName; vendor.MiddleName = vendorVM.middleName; vendor.NickName = vendorVM.nickName; vendor.LastName = vendorVM.lastName; vendor.MobileNo = vendorVM.mobile; vendor.ReferredBy = vendorVM.referredBy; vendor.CreatedBy = vendorVM.createdBy; vendor.ModifiedBy = vendorVM.modifiedBy; using (_dbContext = new AccountdbContext()) { //Save the vendor entity first........ _dbContext.Vendor.Add(vendor); _dbContext.SaveChanges(); response.isSuccess = true; //update the vendorid from db to viewModel............................ response.recordId = vendor.VendorId; vendorVM.id = response.recordId; EfDbContext.VendorDetails vendorDetails = new EfDbContext.VendorDetails() { VendorId = vendorVM.id, AlternateMobile = vendorVM.alternateMobile, HomePhone = vendorVM.homePhone, Email = vendorVM.email, Address = vendorVM.address, City = vendorVM.city, State = vendorVM.state }; _dbContext.VendorDetails.Add(vendorDetails); _dbContext.SaveChanges(); ////Loop all the address list and update the address in the db.................... //if (vendorVM.VendorAddressList.Any()) //{ // foreach (var item in vendorVM.VendorAddressList) // { // _dbContext.VendorDetails.Add(ConstructVendorAddressAsPerContext(item, vendorVM.id)); // } //} } return(response); }
public SalesViewModel AddSales(SalesViewModel data) { try { _dbContext.Sales.Add(ConstructSalesAsPerContext(data)); _dbContext.SaveChanges(); } catch (Exception) { throw; } return(data); }
public CommonResponseViewModel AddExpense(ExpenseViewModel expenseVM) { var responseVM = new CommonResponseViewModel(); try { var expenseDBModel = new EfDbContext.Expenses(); ConstructExpenseDBModel(expenseVM, ref expenseDBModel); bool isDuplicate = CheckIsDuplicate(expenseVM); if (isDuplicate) { responseVM.message = "Expense Name already exists"; return(responseVM); } using (_dbContext = new AccountdbContext()) { _dbContext.Expenses.Add(expenseDBModel); _dbContext.SaveChanges(); responseVM.isSuccess = true; responseVM.recordId = expenseDBModel.ExpenseId; } } catch (Exception ex) { throw ex; } return(responseVM); }
public CommonResponseViewModel UpdateExpense(ExpenseViewModel expenseVM) { var responseVM = new CommonResponseViewModel(); try { bool isDuplicate = CheckIsDuplicate(expenseVM); if (isDuplicate) { responseVM.message = "Expense Name already exists"; return(responseVM); } using (_dbContext = new AccountdbContext()) { var expenseDBModel = _dbContext.Expenses.Where(e => e.ExpenseId.Equals(expenseVM.id)).FirstOrDefault(); if (expenseDBModel != null) { ConstructExpenseDBModel(expenseVM, ref expenseDBModel, true); _dbContext.Update(expenseDBModel); _dbContext.SaveChanges(); responseVM.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(responseVM); }
public CommonResponseViewModel UpdateStock(StockInViewModel stockInVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { using (_dbContext = new AccountdbContext()) { var dbStockIn = _dbContext.StockIn.Where(s => s.StockId.Equals(stockInVM.id)).FirstOrDefault(); if (dbStockIn != null) { dbStockIn.Quantity = stockInVM.totalQuantity; dbStockIn.CreatedDate = stockInVM.createdDate.HasValue ? stockInVM.createdDate.Value : dbStockIn.CreatedDate; dbStockIn.UpdatedDate = DateTime.Now; _dbContext.StockIn.Update(dbStockIn); _dbContext.SaveChanges(); response.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(response); }
private void AddVendorPaymentToDb(VendorPayments vendorPayment) { using (_dbContext = new AccountdbContext()) { _dbContext.VendorPayments.Add(vendorPayment); _dbContext.SaveChanges(); } }
public CommonResponseViewModel UpdateCustomer(CustomerViewModel customerVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { using (_dbContext = new AccountdbContext()) { var customer = _dbContext.Customer.Where(c => c.CustId.Equals(customerVM.id)).FirstOrDefault(); if (customer != null) { customer.FirstName = customerVM.firstName; customer.MiddleName = customerVM.middleName; //customer.NickName = customerVM.nickName; customer.LastName = customerVM.lastName; customer.Mobile = customerVM.mobile; customer.ReferredBy = customerVM.referredBy; customer.CreatedBy = customerVM.createdBy; customer.ModifiedBy = customerVM.modifiedBy; customer.ModifiedDate = DateTime.Now; _dbContext.Update(customer); var customerDetails = _dbContext.CustomerDetails.Where(c => c.CustId.Equals(customerVM.id)).FirstOrDefault(); if (customerDetails != null) { customerDetails.CustId = customerVM.id; customerDetails.AlternateMobile = customerVM.alternateMobile; customerDetails.HomePhone = customerVM.homePhone; customerDetails.OfficePhone = customerVM.officePhone; customerDetails.Email = customerVM.email; customerDetails.Address = customerVM.address; customerDetails.City = customerVM.city; customerDetails.State = customerVM.state; customerDetails.ShopName = customerVM.shopName; customerDetails.ShopLocation = customerVM.shopLocation; _dbContext.Update(customerDetails); } _dbContext.SaveChanges(); response.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(response); }
public CommonResponseViewModel UpdateVendor(VendorViewModel vendorVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { using (_dbContext = new AccountdbContext()) { var vendor = _dbContext.Vendor.Where(v => v.VendorId.Equals(vendorVM.id)).FirstOrDefault(); if (vendor != null) { vendor.FirstName = vendorVM.firstName; vendor.MiddleName = vendorVM.middleName; //vendor.NickName = vendorVM.nickName; vendor.LastName = vendorVM.lastName; vendor.MobileNo = vendorVM.mobile; vendor.ReferredBy = vendorVM.referredBy; vendor.CreatedBy = vendorVM.createdBy; vendor.ModifiedBy = vendorVM.modifiedBy; vendor.ModifiedDate = DateTime.Now; _dbContext.Update(vendor); var vendorDetails = _dbContext.VendorDetails.Where(c => c.VendorId.Equals(vendorVM.id)).FirstOrDefault(); if (vendorDetails != null) { vendorDetails.VendorId = vendorVM.id; vendorDetails.AlternateMobile = vendorVM.alternateMobile; vendorDetails.HomePhone = vendorVM.homePhone; vendorDetails.Email = vendorVM.email; vendorDetails.Address = vendorVM.address; vendorDetails.City = vendorVM.city; vendorDetails.State = vendorVM.state; _dbContext.Update(vendorDetails); } _dbContext.SaveChanges(); response.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(response); }
public bool DeleteVendorById(int id) { bool result = false; try { using (_dbContext = new AccountdbContext()) { var vendor = _dbContext.Vendor.Where(e => e.VendorId.Equals(id)).FirstOrDefault(); vendor.IsActive = false; _dbContext.Vendor.Update(vendor); _dbContext.SaveChanges(); } } catch (Exception ex) { throw ex; } return(result); }
public bool DeleteCustomerById(int id) { bool result = false; try { using (_dbContext = new AccountdbContext()) { var cust = _dbContext.Customer.Where(e => e.CustId.Equals(id)).FirstOrDefault(); cust.IsActive = false; _dbContext.Customer.Update(cust); _dbContext.SaveChanges(); result = true; } } catch (Exception ex) { throw ex; } return(result); }
public bool DeleteExpenseById(int id) { bool result = false; try { using (_dbContext = new AccountdbContext()) { var expense = _dbContext.Expenses.Where(e => e.ExpenseId.Equals(id)).FirstOrDefault(); //expense.IsActive = false; //_dbContext.Expenses.Update(expense); _dbContext.Expenses.Remove(expense); _dbContext.SaveChanges(); result = true; } } catch (Exception ex) { throw ex; } return(result); }
public bool DeleteStockById(int id) { bool result = false; try { using (_dbContext = new AccountdbContext()) { var stockInfo = _dbContext.StockIn.Where(e => e.StockId.Equals(id)).FirstOrDefault(); stockInfo.IsActive = false; _dbContext.StockIn.Update(stockInfo); _dbContext.SaveChanges(); result = true; } } catch (Exception ex) { throw ex; } return(result); }
public CommonResponseViewModel AddStock(StockInViewModel stockInVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { using (_dbContext = new AccountdbContext()) { var dbStockIn = ConstructStockInAddressAsPerContext(stockInVM); dbStockIn.CreatedDate = stockInVM.createdDate.HasValue ? stockInVM.createdDate.Value : DateTime.Now; _dbContext.StockIn.Add(dbStockIn); _dbContext.SaveChanges(); response.recordId = dbStockIn.StockId; response.isSuccess = true; } } catch (Exception ex) { throw ex; } return(response); }
public CommonResponseViewModel AddCustomer(CustomerViewModel customerVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { var cust = new EfDbContext.Customer(); cust.FirstName = customerVM.firstName; cust.MiddleName = customerVM.middleName; cust.NickName = customerVM.nickName; cust.LastName = customerVM.lastName; cust.Mobile = customerVM.mobile; cust.ReferredBy = customerVM.referredBy; cust.CreatedBy = customerVM.createdBy; cust.ModifiedBy = customerVM.modifiedBy; using (_dbContext = new AccountdbContext()) { //Save the customer entity first........ _dbContext.Customer.Add(cust); _dbContext.SaveChanges(); response.isSuccess = true; //update the custid from db to viewModel............................ response.recordId = cust.CustId; customerVM.id = response.recordId; EfDbContext.CustomerDetails customerDetails = new EfDbContext.CustomerDetails() { CustId = customerVM.id, AlternateMobile = customerVM.alternateMobile, HomePhone = customerVM.homePhone, OfficePhone = customerVM.officePhone, Email = customerVM.email, Address = customerVM.address, City = customerVM.city, State = customerVM.state, ShopName = customerVM.shopName, ShopLocation = customerVM.shopLocation }; _dbContext.CustomerDetails.Add(customerDetails); _dbContext.SaveChanges(); //Loop all the address list and update the address in the db.................... //if (customerVM.CustAddressList != null && customerVM.CustAddressList.Any()) //{ // foreach (var item in customerVM.CustAddressList) // { // _dbContext.CustomerDetails.Add(ConstructCustAddressAsPerContext(item, customerVM.id)); // } //} } } catch (Exception ex) { throw ex; } return(response); }