Пример #1
0
        public static bool SubmitChanges(Branch item)
        {
            if (item != null)
            {
                dataContext = new RavenPXDataContext();

                if (item.ID != Guid.Empty)
                {
                    Branch oldBranch = GetBranch(item.ID, dataContext);

                    if (oldBranch != null)
                    {
                        oldBranch.LocationName = item.LocationName;

                        oldBranch.Address = item.Address;

                        oldBranch.PhoneNumber = item.PhoneNumber;

                        oldBranch.ZipCode = item.ZipCode;

                        dataContext.SubmitChanges();

                        if (GetBranch(oldBranch) != null)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        //should not happen
                    }
                }
                else
                {
                    Branch newBranch = new Branch();

                    newBranch.ID = Guid.NewGuid();

                    newBranch.LocationName = item.LocationName;

                    newBranch.Address = item.Address;

                    newBranch.PhoneNumber = item.PhoneNumber;

                    newBranch.ZipCode = item.ZipCode;

                    dataContext.Branches.InsertOnSubmit(newBranch);

                    dataContext.SubmitChanges();

                    if (GetBranch(newBranch) != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public static List <XSetting> GetXSettingsByModuleID(int moduleID)
        {
            dataContext = new RavenPXDataContext();

            List <XSetting> items = (from p in dataContext.XSettings
                                     where p.ModuleID == moduleID
                                     select p).ToList();

            return(items);
        }
Пример #3
0
        public static Branch GetBranch(Guid ID, RavenPXDataContext _dataContext)
        {
            List <Branch> items = (from p in _dataContext.Branches
                                   orderby p.ID descending
                                   select p).ToList();

            if (items.Count > 0)
            {
                return(items.First());
            }

            return(null);
        }
Пример #4
0
        static XSetting GetSetting(int appKey, RavenPXDataContext _dataContext)
        {
            List <XSetting> items = (from p in _dataContext.XSettings
                                     where p.AppKey == appKey
                                     select p).ToList();

            if (items.Count > 0)
            {
                return(items.First());
            }

            return(null);
        }
Пример #5
0
        public static List <Branch> GetBranches()
        {
            dataContext = new RavenPXDataContext();

            List <Branch> items = (from p in dataContext.Branches
                                   orderby p.ID descending
                                   select p).ToList();

            if (items.Count > 0)
            {
                return(items);
            }

            return(new List <Branch>());
        }
Пример #6
0
        public static bool Delete(Guid ID)
        {
            dataContext = new RavenPXDataContext();

            Branch item = GetBranch(ID, dataContext);

            if (item != null)
            {
                dataContext.Branches.DeleteOnSubmit(item);

                dataContext.SubmitChanges();

                if (GetBranch(ID, dataContext) == null)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
        public static Branch GetBranch(Branch item)
        {
            dataContext = new RavenPXDataContext();

            List <Branch> items = (from p in dataContext.Branches
                                   orderby p.ID descending
                                   where p.ID == item.ID &&
                                   p.LocationName == item.LocationName &&
                                   p.Address == item.Address &&
                                   p.PhoneNumber == item.PhoneNumber &&
                                   p.ZipCode == item.ZipCode
                                   select p).ToList();

            if (items.Count > 0)
            {
                return(items.First());
            }

            return(null);
        }
Пример #8
0
        public static bool SubmitChanges(List <XSetting> items)
        {
            if (items.Count > 0)
            {
                dataContext = new RavenPXDataContext();

                List <XSetting> insertList = new List <XSetting>();

                foreach (XSetting item in items)
                {
                    XSetting refItem = GetSetting((int)item.AppKey, dataContext);

                    if (refItem != null)
                    {
                        refItem.Value = item.Value;
                    }
                    else //create entry
                    {
                        refItem = new XSetting {
                            ID = Guid.NewGuid(), ModuleID = item.ModuleID, AppKey = item.AppKey, Value = item.Value
                        };

                        insertList.Add(refItem);
                    }
                }

                dataContext.XSettings.InsertAllOnSubmit(insertList);

                dataContext.SubmitChanges();

                //place a validation here
                return(true);
            }

            //nothing to save
            return(false);
        }