Beispiel #1
0
        public static bl_GuestCouples_Result Add(bl_GuestCouples info)
        {
            using (var metadata = DataAccess.getDesktopMetadata())
            {
                var qDuplicate = (from row in metadata.db_GroupCouple
                                  where row.CoupleName.ToLower().Trim() == info.CoupleName.ToLower().Trim()
                                  select row).FirstOrDefault();

                if (qDuplicate == null)
                {
                    var newGroupCouple = new db_GroupCouple
                    {
                        CoupleName = info.CoupleName,
                    };

                    metadata.db_GroupCouple.Add(newGroupCouple);
                    metadata.SaveChanges();

                    var result = new bl_GuestCouples_Result
                    {
                        hasError = false,
                    };
                    return(result);
                }
                else
                {
                    var result = new bl_GuestCouples_Result
                    {
                        hasError  = true,
                        ErrorText = "Couple Name already exist for another Couple"
                    };
                    return(result);
                }
            }
        }
Beispiel #2
0
        public static bl_GuestCouples_Result Edit(bl_GuestCouples info)
        {
            using (var metadata = DataAccess.getDesktopMetadata())
            {
                //Get original guest record
                var qGuest = (from row in metadata.db_GroupCouple
                              where row.groupCoupleID == info.groupCoupleID
                              select row).FirstOrDefault();

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


                var item = qGuest;
                if (item == null)
                {
                    throw new NullReferenceException("No Guest Couple found");
                }

                var duplicate = qDuplicate;
                if (duplicate == null)
                {
                    item.CoupleName = info.CoupleName;

                    metadata.SaveChanges();

                    var result = new bl_GuestCouples_Result
                    {
                        hasError = false
                    };
                    return(result);
                }
                else
                {
                    var result = new bl_GuestCouples_Result
                    {
                        hasError  = true,
                        ErrorText = "Couple Name already exist for another Couple"
                    };
                    return(result);
                }
            }
        }