Example #1
0
        public static bool AddSection(Section section)
        {
            //here i'll disect the whole object into different objects
            //Ill also assign Id's and Rec Id's
            if (section.SectionId == Guid.Empty)
            {
                var sectionId = Guid.NewGuid();
                var ratings   = section.Ratings;
                var discounts = section.Discounts;
                var loadings  = section.Loadings;

                try
                {
                    foreach (Rating rating in ratings)
                    {
                        DbContext.AddRatings(rating, sectionId);
                    }
                    foreach (Discount discount in discounts)
                    {
                        DbContext.AddDiscounts(discount, sectionId);
                    }
                    foreach (Loading loading in loadings)
                    {
                        DbContext.AddLoadings(loading, sectionId);
                    }

                    section.SectionId = sectionId;
                    DbContext.AddSection(section);
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                var ratings   = section.Ratings;
                var discounts = section.Discounts;
                var loadings  = section.Loadings;

                try
                {
                    foreach (Rating rating in ratings)
                    {
                        if (rating.RatingId == Guid.Empty)
                        {
                            DbContext.AddRatings(rating, section.SectionId);
                        }
                        else
                        {
                            DbContext.UpdateRating(rating);
                        }
                    }
                    foreach (Discount discount in discounts)
                    {
                        if (discount.DiscountId == Guid.Empty)
                        {
                            DbContext.AddDiscounts(discount, section.SectionId);
                        }
                        else
                        {
                            DbContext.UpdateDiscounts(discount);
                        }
                    }
                    foreach (Loading loading in loadings)
                    {
                        if (loading.LoadingId == Guid.Empty)
                        {
                            DbContext.AddLoadings(loading, section.SectionId);
                        }
                        else
                        {
                            DbContext.UpdateLoading(loading);
                        }
                    }


                    DbContext.UpdateSection(section);
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
        }