public int CreateNewOrganization(string projorganization)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            try
            {
                Organization org = new Organization();
                db.Organizations.InsertOnSubmit(org);
                db.SubmitChanges();

                General gen = new General();
                gen.OrgID  = org.OrgID;
                gen.NameRu = projorganization;
                db.Generals.InsertOnSubmit(gen);
                db.SubmitChanges();

                return(org.OrgID);
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                return(-1);
            }
        }
Пример #2
0
        public void UpdateBudget(int id, string infoBox, Decimal Cancellation, Decimal Returned)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                var budgetToUpdate = (from b in db.Budgets
                                      where b.BudgetID == id
                                      select b).First();

                if (budgetToUpdate != null)
                {
                    budgetToUpdate.InfoBox      = infoBox;
                    budgetToUpdate.Cancellation = Cancellation;
                    budgetToUpdate.Returned     = Returned;

                    // db.Budgets.Attach(budgetToUpdate);
                    db.Refresh(RefreshMode.KeepCurrentValues, budgetToUpdate);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                //   result = false;
            }

            //return result;
        }
Пример #3
0
        public bool CreatePageAccess(PageAccess pa)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                //TODO: I should also check if such project and user exists.

                if (!db.PageAccesses.Any(l => l.Controller == pa.Controller && l.Action == pa.Action && l.RoleId == pa.RoleId)) // !if exists.
                {
                    db.PageAccesses.InsertOnSubmit(pa);
                }
                else
                {
                    return(false);
                }

                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #4
0
        public bool DeletePageAccess(int?id)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            bool result = true;

            try
            {
                var toDelete = (from s in db.PageAccesses
                                where s.ID == id
                                select s).FirstOrDefault();

                if (toDelete != null)
                {
                    db.PageAccesses.DeleteOnSubmit(toDelete);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// It either updates existing account or
        /// if such account does not exist then inserts.
        /// </summary>
        /// <param name="account"></param>
        public bool SaveAccount(SSPStaff account)
        {
            BOTADataContext db = new BOTADataContext(connectString);
            {
                try
                {
                    if (account.SSPStaffID > 0)
                    {
                        db.SSPStaffs.Attach(account);
                        db.Refresh(RefreshMode.KeepCurrentValues, account);
                    }
                    else
                    {
                        db.SSPStaffs.InsertOnSubmit(account);
                    }
                    db.SubmitChanges();

                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
        public bool DeleteOrgOtherFunders(int id)
        {
            bool result = true;

            try
            {
                BOTADataContext db = new BOTADataContext(connectString);

                //using (BOTADataContext db)
                {
                    OtherFunder item = (from o in db.OtherFunders
                                        where o.OtherFundID == id
                                        select o).FirstOrDefault();
                    if (item != null)
                    {
                        db.OtherFunders.DeleteOnSubmit(item);
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                //Log4Net uses its dll, bin/Log4Net.config -> has C:/Logs/errors2.txt
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                result = false;
            }


            return(result);
        }
        public bool DeleteOrgContact(int id)
        {
            bool result = true;

            try
            {
                BOTADataContext db = new BOTADataContext(connectString);

                //using (BOTADataContext db)
                {
                    Contact item = (from conts in db.Contacts
                                    where conts.ContactID == id
                                    select conts).First();
                    if (item != null)
                    {
                        db.Contacts.DeleteOnSubmit(item);
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                result = false;
            }


            return(result);
        }
Пример #8
0
        public bool UpdateBudgetInitialAmount(int initialamt, int budgetID)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                Budget budget = (from b in db.Budgets
                                 where b.BudgetID == budgetID
                                 select b).FirstOrDefault();

                budget.ContractInitialAmt = initialamt;

                //db.Budgets.Attach();
                db.Refresh(RefreshMode.KeepCurrentValues, budget);
                db.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }

            //return result;
        }
        public bool InsertNewOrgAddress(int id)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            try
            {
                Address addr = new Address();

                if (!db.Addresses.Any(l => l.OrgID == id)) // if first address of org then it is the default.
                {
                    addr.isLegalAddress = true;
                }

                addr.OrgID = id;
                db.Addresses.InsertOnSubmit(addr);
                db.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                return(false);
            }
        }
Пример #10
0
        /// <summary>
        /// Inserts staff into project.
        /// </summary>
        /// <param name="SSPStaffID"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool InsertSSPStaffIntoProject(int SSPStaffID, int id)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                //TODO: I should also check if such project and user exists.

                if (!db.SSPStaffProjects.Any(l => l.SSPStaffID == SSPStaffID && l.ProjectID == id)) // !if exists.
                {
                    SSPStaffProject sspproject = new SSPStaffProject();
                    sspproject.ProjectID  = id;
                    sspproject.SSPStaffID = SSPStaffID;

                    db.SSPStaffProjects.InsertOnSubmit(sspproject);
                }
                else
                {
                    return(false);
                }

                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #11
0
        public bool DeleteSSPStaffFromProject(int SSPStaffID, int id)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            bool result = true;

            try
            {
                var toDelete = (from s in db.SSPStaffProjects
                                where s.ProjectID == id && s.SSPStaffID == SSPStaffID
                                select s).FirstOrDefault();

                if (toDelete != null)
                {
                    db.SSPStaffProjects.DeleteOnSubmit(toDelete);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #12
0
        public bool Insert(UserActionLog item)
        {
            bool result = true;

            try
            {
                db.UserActionLogs.InsertOnSubmit(item);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(ProjectEventRepository), "-------------User Action Logs- Insert-------------------------", ex);
                result = false;
            }
            return(result);
        }
        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)
            {
            }
        }
Пример #14
0
        public bool CreateReportPeriod(ReportPeriodListR item)
        {
            BOTADataContext db     = new BOTADataContext(connectString);
            bool            result = true;

            try
            {
                db.ReportPeriodListRs.InsertOnSubmit(item);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
Пример #15
0
        public bool UpdateStaffProject(int id, List <int> current)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            {
                try
                {
                    var sspproj = from a in db.SSPStaffProjects
                                  where a.ProjectID == id
                                  select a;

                    foreach (var vsp in sspproj)
                    {
                        if (current != null)
                        {
                            if (current.Any(s => s == vsp.SSPStaffID))
                            {
                                vsp.Active = true;
                            }
                            else
                            {
                                vsp.Active = false;
                            }
                        }
                        else
                        {
                            vsp.Active = false;
                        }
                    }


                    // db.SSPStaffProjects.AttachAll(sspproj);
                    db.Refresh(RefreshMode.KeepCurrentValues, sspproj);
                    db.SubmitChanges();

                    return(true);
                }
                catch
                {
                    return(false);
                }
            }

            return(false);
        }
Пример #16
0
        /// <summary>
        /// Updates Report Periods.
        /// </summary>
        /// <param name="repperlist"></param>
        /// <returns></returns>
        public bool UpdateReportPeriodList(List <ReportPeriodListR> repperlist)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                db.ReportPeriodListRs.AttachAll(repperlist);
                db.Refresh(RefreshMode.KeepCurrentValues, repperlist);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #17
0
        public bool InsertArticleToReportPeriodR(List <ReportPeriodR> ReportPeriods)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            try
            {
                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(false); //could not insert into Report Periods.
            }

            return(true);
        }
        public bool DeleteOrganization(int ProposalID)
        {
            /*
             * // Get movie to delete
             * var movieToDelete = _db.MovieSet.First(m => m.Id == id);
             *
             * // Delete
             * _db.DeleteObject(movieToDelete);
             * _db.SaveChanges();
             *
             * // Show Index view
             * return RedirectToAction("Index");  */



            bool result = true;

            try
            {
                BOTADataContext db = new BOTADataContext(connectString);

                //using (BOTADataContext db)
                {
                    Organization item = (from projects in db.Projects
                                         join organization in db.Organizations
                                         on projects.Organization.OrgID equals organization.OrgID
                                         where projects.ProjectID == ProposalID
                                         select organization).First();
                    db.Organizations.DeleteOnSubmit(item);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                result = false;
            }


            return(result);
        }
        public bool InsertNewOrgContact(int id)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            try
            {
                Contact cont = new Contact();
                cont.OrgID = id;
                db.Contacts.InsertOnSubmit(cont);
                db.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                return(false);
            }
        }
        public bool InsertNewOrgOtherFunders(int id)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            try
            {
                OtherFunder o = new OtherFunder();
                o.OrgID = id;
                db.OtherFunders.InsertOnSubmit(o);
                db.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                return(false);
            }
        }
        /// <summary>
        /// Updates All addreses of current organization.
        /// </summary>
        /// <param name="OrgAddresses"></param>
        /// <returns></returns>
        public bool UpdateOtherFunders(IEnumerable <OtherFunder> enumotherfunders)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                db.OtherFunders.AttachAll(enumotherfunders);
                db.Refresh(RefreshMode.KeepCurrentValues, enumotherfunders);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                result = false;
            }

            return(result);
        }
        public bool UpdateOrganization(Organization org, int ProposalID)
        {
            bool result = true;

            try
            {
                BOTADataContext db = new BOTADataContext(connectString);

                {
                    Organization item = (from projects in db.Projects
                                         join organization in db.Organizations //.Include("General")
                                         on projects.Organization.OrgID equals organization.OrgID
                                         where projects.ProjectID == ProposalID
                                         select organization).First();

                    //join legstatus in db.LegalStatus
                    //                  on projects.Organization.OrgID equals legstatus.OrgID


                    //General Info Update.
                    item.General.Name           = org.General.Name;
                    item.LegalStatus.LegSListID = org.LegalStatus.LegSListID;
                    item.General.FiscalYearEnd  = org.General.FiscalYearEnd;
                    item.General.Notes          = org.General.Notes;
                    item.Contacts = org.Contacts;



                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                result = false;
            }


            return(result);
        }
Пример #23
0
        public bool UpdatePageAccess(PageAccess pa)
        {
            BOTADataContext db = new BOTADataContext(connectString);
            {
                try
                {
                    if (pa.ID > 0)
                    {
                        db.PageAccesses.Attach(pa);
                        db.Refresh(RefreshMode.KeepCurrentValues, pa);
                    }

                    db.SubmitChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Пример #24
0
        public bool DeleteReportPeriod(int RepperID, int BudgetID)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            bool result = true;

            try
            {
                var toDelete = (from r in db.ReportPeriodListRs
                                where r.ReportPeriodID == RepperID && r.BudgetID == BudgetID
                                select r).First();
                db.ReportPeriodListRs.DeleteOnSubmit(toDelete);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #25
0
        public void UpdateCategoriesValues(List <FinArticleCategoryR> FinArticleCategory)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                /*var oldItem  = (from p in db.ProjectEvents
                 *             where p.EventID == item.EventID
                 *             select p).First();*/
                db.FinArticleCategoryRs.AttachAll(FinArticleCategory);
                db.Refresh(RefreshMode.KeepCurrentValues, FinArticleCategory);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                //   result = false;
            }

            //return result;
        }
Пример #26
0
        public bool DeleteArticleCat(int?FinArticleCatID, int?BudgetID)
        {
            BOTADataContext db = new BOTADataContext(connectString);

            bool result = true;

            try
            {
                var toDelete = (from c in db.FinArticleCategoryRs
                                where c.BudgetID == BudgetID.Value && c.FinArticleCatID == FinArticleCatID
                                select c).First();
                db.FinArticleCategoryRs.DeleteOnSubmit(toDelete);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Пример #27
0
        public void UpdateReportPeriodTrans(List <ReportPeriodR> ReportPeriods)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                /*var oldItem  = (from p in db.ProjectEvents
                 *             where p.EventID == item.EventID
                 *             select p).First();*/
                db.ReportPeriodRs.AttachAll(ReportPeriods);
                db.Refresh(RefreshMode.KeepCurrentValues, ReportPeriods);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                //   result = false;
            }

            //return result;
        }
        /// <summary>
        /// Updates Organization General.
        /// LegalStatus: If exists then update, if no then insert.
        /// </summary>
        /// <param name="gen"></param>
        /// <returns></returns>
        public bool UpdateOrganizationGeneral(General gen)
        {
            bool            result = true;
            BOTADataContext db     = new BOTADataContext(connectString);

            try
            {
                db.Generals.Attach(gen);
                db.Refresh(RefreshMode.KeepCurrentValues, gen);

                //db.ExecuteCommand("DELETE FROM addresses WHERE ContactID={0} and AddressTypeID={1}", contactID, addressTypeID);
                // gen.Organization.LegalStatus.Detach();

                //check if legalstaus exists.

                /* var legstat = (from l in db.LegalStatus
                 *              where l.OrgID == gen.OrgID
                 *              select l).FirstOrDefault(); */


                //if (legstat == null) //if it does not exist.
                if (!db.LegalStatus.Any(l => l.OrgID == gen.OrgID)) // !if exists.
                {
                    //Insert
                    LegalStatus lstat = new LegalStatus();
                    lstat.OrgID        = gen.OrgID;
                    lstat.LegSListID   = gen.Organization.LegalStatus.LegSListID;
                    lstat.SelectedDate = gen.Organization.LegalStatus.SelectedDate;
                    db.LegalStatus.InsertOnSubmit(lstat);
                }
                else
                {  //try to update.
                   // legstat.Detach();
                   // legstat.LegSListID = gen.Organization.LegalStatus.LegSListID;
                   // db.LegalStatus.Attach(legstat);
                    db.Refresh(RefreshMode.KeepCurrentValues, gen.Organization.LegalStatus);
                }

                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(OrganizationRepository), "----------------------------------------------", ex);
                result = false;
            }

            return(result);

/*
 *         try
 *         {
 *
 *             BOTADataContext db = new BOTADataContext(connectString);
 *
 *             { General genitem = (from organization in db.Organizations
 *                                    join general in db.Generals
 *                                    on organization.OrgID equals general.OrgID
 *                                    where general.OrgID == gen.Organization.OrgID
 *                                    select general).First();
 *
 *                 genitem.Name = gen.Name;
 *                 genitem.Organization.LegalStatus.LegSListID = gen.Organization.LegalStatus.LegSListID;
 *                 genitem.FiscalYearEnd = gen.FiscalYearEnd;
 *                 genitem.Notes = gen.Notes;
 *                 db.SubmitChanges();
 *
 *             }
 *         }
 *         catch (Exception ex)
 *         {
 *             result = false;
 *         }
 *
 *         return result; */
        }
        public bool InsertIndicatorLabel(IndicatorLabel item)
        {
            bool result = true;

            try
            {
                db.IndicatorLabels.InsertOnSubmit(item);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                Log.EnsureInitialized();
                Log.Error(typeof(IndicatorRepository), "----------------------------------------------", ex);
                result = false;
                // throw ex;
            }
            return(result);
        }
Пример #30
0
        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);
        }