public void saveFile(string month, int year, string type, int customerId, HttpPostedFile files) { using (CalfScramblerEntities cs = new CalfScramblerEntities()) { var header = cs.clfs_winner_monthly_headers.Where(x => x.EXHIBITOR_ID == customerId && x.REPORTING_MONTH == month && x.SHOW_YEAR == year).FirstOrDefault(); if (header == null) { header = new clfs_winner_monthly_headers { EXHIBITOR_ID = customerId, REPORTING_MONTH = month, SHOW_YEAR = year }; cs.clfs_winner_monthly_headers.Add(header); cs.SaveChanges(); } Stream stream = files.InputStream; BinaryReader reader = new BinaryReader(stream); byte[] imgByte = reader.ReadBytes((int)stream.Length); if (type == "corres") { cs.clfs_winner_monthly_documents.Add(new clfs_winner_monthly_documents { HEADER_ID = header.HEADER_ID, CORRESPONDENCE = imgByte, CORR_FILE_NAME = files.FileName, CORR_FILE_TYPE = GetFileExtension(files.FileName), CORR_SUBMIT_DATE = DateTime.Now }); cs.clfs_winner_monthly_documents.Add(new clfs_winner_monthly_documents { HEADER_ID = header.HEADER_ID, CORRESPONDENCE = imgByte, CORR_FILE_NAME = files.FileName, CORR_FILE_TYPE = GetFileExtension(files.FileName), CORR_SUBMIT_DATE = DateTime.Now }); } else { cs.clfs_winner_monthly_documents.Add(new clfs_winner_monthly_documents { HEADER_ID = header.HEADER_ID, PHOTO = imgByte, PHOTO_FILE_NAME = files.FileName, PHOTO_FILE_TYPE = GetFileExtension(files.FileName), PHOTO_SUBMIT_DATE = DateTime.Now }); } cs.SaveChanges(); } }
public bool AddExpense(ExpenseEntity e) { using (CalfScramblerEntities cs = new CalfScramblerEntities()) { var header = cs.clfs_winner_monthly_headers.Where(x => x.EXHIBITOR_ID == e.customerid && x.REPORTING_MONTH == e.month && x.SHOW_YEAR == e.year).FirstOrDefault(); if (header == null) { header = new clfs_winner_monthly_headers { EXHIBITOR_ID = e.customerid, REPORTING_MONTH = e.month, SHOW_YEAR = e.year }; cs.clfs_winner_monthly_headers.Add(header); cs.SaveChanges(); } cs.clfs_winner_monthly_expenses.Add(new clfs_winner_monthly_expenses { HEADER_ID = header.HEADER_ID, EXPENSE_TYPE = e.expensetype, QUANTITY = e.quantity, UNIT_COST = e.unitcost }); cs.SaveChanges(); return(true); } }