Beispiel #1
0
        public static bl_Registry_Result UpdateSelect(bl_Registry info)
        {
            using (var metadata = DataAccess.getDesktopMetadata())
            {
                //Get original guest record
                var qReg = (from row in metadata.db_Registry
                            where row.registryID == info.registryID
                            select row).FirstOrDefault();

                var item = qReg;
                if (item == null)
                {
                    throw new NullReferenceException("No Gift found. Refresh Page");
                }

                item.isSelected     = info.isSelected;
                item.selectedUserID = info.selectedUserID;

                metadata.SaveChanges();

                var result = new bl_Registry_Result
                {
                    hasError = false
                };
                return(result);
            }
        }
Beispiel #2
0
        public static bl_Registry_Result Edit(bl_Registry info)
        {
            using (var metadata = DataAccess.getDesktopMetadata())
            {
                //Get original guest record
                var qReg = (from row in metadata.db_Registry
                            where row.registryID == info.registryID
                            select row).FirstOrDefault();

                //Check if their is a duplicate
                var qDuplicate = (from row in metadata.db_Registry
                                  where row.GiftName.ToLower().Trim() == info.GiftName.ToLower().Trim() &&
                                  row.registryID != info.registryID
                                  select row).FirstOrDefault();


                var item = qReg;
                if (item == null)
                {
                    throw new NullReferenceException("No Gift found. Refresh Page");
                }

                var duplicate = qDuplicate;
                if (duplicate == null && item.isSelected == false)
                {
                    item.GiftName = info.GiftName;

                    metadata.SaveChanges();

                    var result = new bl_Registry_Result
                    {
                        hasError = false
                    };
                    return(result);
                }
                else if (duplicate == null && item.isSelected == true)
                {
                    var result = new bl_Registry_Result
                    {
                        hasError  = true,
                        ErrorText = "Cannot edit a gift already chosen by a Guest"
                    };
                    return(result);
                }
                else
                {
                    var result = new bl_Registry_Result
                    {
                        hasError  = true,
                        ErrorText = "Gift already exist"
                    };
                    return(result);
                }
            }
        }
Beispiel #3
0
        public static bl_Registry_Result Add(bl_Registry info)
        {
            using (var metadata = DataAccess.getDesktopMetadata())
            {
                var qDuplicate = (from row in metadata.db_Registry
                                  where row.GiftName.ToLower().Trim() == info.GiftName.ToLower().Trim()
                                  select row).FirstOrDefault();

                if (qDuplicate == null)
                {
                    var newRegistry = new db_Registry
                    {
                        GiftName   = info.GiftName,
                        isSelected = false,
                    };

                    metadata.db_Registry.Add(newRegistry);
                    metadata.SaveChanges();

                    var result = new bl_Registry_Result
                    {
                        hasError = false,
                    };
                    return(result);
                }
                else
                {
                    var result = new bl_Registry_Result
                    {
                        hasError  = true,
                        ErrorText = "Gift already exist"
                    };
                    return(result);
                }
            }
        }