public void InsertNewCatName(string NewCatName) { BOTADataContext db = new BOTADataContext(connectString); FinArtCatListR fcatlist = new FinArtCatListR(); fcatlist.FinArticleCatName = NewCatName; try { db.FinArtCatListRs.InsertOnSubmit(fcatlist); db.SubmitChanges(); } catch (Exception ex) { } }
public int AddFinArticleCategory(int id, int FinCatSel) { BOTADataContext db = new BOTADataContext(connectString); //Check if Any Report Periods Exist! if (!db.ReportPeriodListRs.Any(l => l.BudgetID == id)) // !if exists. { return(-2); //this means no ReportPeriods created yet. } FinArticleCategoryR fcat = new FinArticleCategoryR(); // fcat.FinArticleCatListID = FinCatSel; FinArtCatListR fcatr = (from ls in db.FinArtCatListRs where ls.FinArticleCatListID == FinCatSel select ls).FirstOrDefault(); fcat.FinArticleCatText = fcatr.FinArticleCatName; fcat.BudgetID = id; fcat.Price = 0; fcat.FinCatID = FinCatSel; try { db.FinArticleCategoryRs.InsertOnSubmit(fcat); db.SubmitChanges(); } catch (Exception ex) { //Log4Net uses its dll, bin/Log4Net.config -> has C:/Logs/errors2.txt Log.EnsureInitialized(); Log.Error(typeof(ProjectRepository), "Exception catched while Insert Project.", ex); return(-1); //could not insert new Category somehow. } try { IEnumerable <ReportPeriodListR> ReportPeriodsList = from ls in db.ReportPeriodListRs where ls.BudgetID == id select ls; List <ReportPeriodR> ReportPeriods = new List <ReportPeriodR>(); foreach (ReportPeriodListR rep in ReportPeriodsList) { ReportPeriodR repper = new ReportPeriodR(); repper.ReportPeriodID = rep.ReportPeriodID; repper.FinArticleCatID = fcat.FinArticleCatID; repper.Amount = 0; ReportPeriods.Add(repper); } db.ReportPeriodRs.InsertAllOnSubmit(ReportPeriods.AsEnumerable()); db.SubmitChanges(); } catch (Exception ex) { //Log4Net uses its dll, bin/Log4Net.config -> has C:/Logs/errors2.txt Log.EnsureInitialized(); Log.Error(typeof(ProjectRepository), "Exception catched while Insert Project.", ex); return(-3); //could not insert into Report Periods. } return(fcat.FinArticleCatID); }