Beispiel #1
0
        public GetAllSponsorsOfExhibitor GetAllSponsorsOfExhibitor(int exhibitorId)
        {
            IEnumerable <GetSponsorsOfExhibitor> getSponsorsOfExhibitors   = null;
            GetAllSponsorsOfExhibitor            getAllSponsorsOfExhibitor = new GetAllSponsorsOfExhibitor();

            getSponsorsOfExhibitors = (from sponsorExhibitor in _context.SponsorExhibitor
                                       join sponsor in _context.Sponsors on sponsorExhibitor.SponsorId equals sponsor.SponsorId
                                       join address in _context.Addresses on sponsor.AddressId equals address.AddressId
                                       join city in _context.Cities on address.CityId equals city.CityId
                                       join state in _context.States on city.StateId equals state.StateId
                                       join zipcode in _context.ZipCodes2 on address.ZipCodeId equals zipcode.ZipCodeId into zipcode1
                                       from zipcode2 in zipcode1.DefaultIfEmpty()
                                       where sponsorExhibitor.IsActive == true && sponsorExhibitor.IsDeleted == false &&
                                       sponsor.IsActive == true && sponsor.IsDeleted == false &&
                                       sponsorExhibitor.ExhibitorId == exhibitorId
                                       select new GetSponsorsOfExhibitor
            {
                SponsorExhibitorId = sponsorExhibitor.SponsorExhibitorId,
                SponsorId = sponsor.SponsorId,
                Sponsor = sponsor.SponsorName,
                ContactName = sponsor.ContactName,
                Phone = sponsor.Phone,
                Address = address.Address,
                City = city.Name,
                State = state.Name,
                Zipcode = zipcode2 != null? Convert.ToInt32(zipcode2.ZipCode):0,
                Email = sponsor.Email,
                Amount = sponsor.AmountReceived,
                SponsorTypeId = sponsorExhibitor.SponsorTypeId,
                SponsorTypeName = (from code in _context.GlobalCodes where code.GlobalCodeId == sponsorExhibitor.SponsorTypeId select code.CodeName).FirstOrDefault(),
                AdTypeName = (from code1 in _context.GlobalCodes where code1.GlobalCodeId == sponsorExhibitor.AdTypeId select code1.CodeName).FirstOrDefault(),
                IdNumber = sponsorExhibitor.SponsorTypeId == (int)SponsorTypes.Class ? Convert.ToString(_context.Classes.Where(x => x.ClassId == Convert.ToInt32(sponsorExhibitor.TypeId)).Select(x => x.ClassNumber).FirstOrDefault())
                                       : (sponsorExhibitor.SponsorTypeId == (int)SponsorTypes.Add ? sponsorExhibitor.TypeId
                                       : Convert.ToString(0)),
            });
            if (getSponsorsOfExhibitors.Count() != 0)
            {
                getAllSponsorsOfExhibitor.getSponsorsOfExhibitors = getSponsorsOfExhibitors.ToList();
                getAllSponsorsOfExhibitor.TotalRecords            = getSponsorsOfExhibitors.Count();
            }
            return(getAllSponsorsOfExhibitor);
        }
        public GetAllSponsorsOfExhibitor GetAllSponsorsOfExhibitor(int exhibitorId)
        {
            List <GetSponsorsOfExhibitor> getSponsorsOfExhibitors   = new List <GetSponsorsOfExhibitor>();
            List <GetSponsorsOfExhibitor> getSponsorsOfExhibitors1  = new List <GetSponsorsOfExhibitor>();
            GetAllSponsorsOfExhibitor     getAllSponsorsOfExhibitor = new GetAllSponsorsOfExhibitor();
            var sponsorTypes = (from gcc in _context.GlobalCodeCategories
                                join gc in _context.GlobalCodes on gcc.GlobalCodeCategoryId equals gc.CategoryId
                                where gcc.CategoryName == "SponsorTypes" && gc.IsDeleted == false && gc.IsActive == true
                                select new GlobalCodeResponse
            {
                GlobalCodeId = gc.GlobalCodeId,
                CodeName = (gc.CodeName == null ? "" : gc.CodeName),
                Description = (gc.Description == null ? String.Empty : gc.Description),
                GlobalCodeCategory = gcc.CategoryName,
                CategoryId = gc.CategoryId,
            }).ToList();
            var adSponsorTypeId    = 0;
            var classSponsorTypeId = 0;

            if (sponsorTypes != null && sponsorTypes.Count > 0)
            {
                adSponsorTypeId    = sponsorTypes.Where(x => x.CodeName == "Ad").Select(x => x.GlobalCodeId).FirstOrDefault();
                classSponsorTypeId = sponsorTypes.Where(x => x.CodeName == "Class").Select(x => x.GlobalCodeId).FirstOrDefault();
            }


            getSponsorsOfExhibitors = (from sponsorExhibitor in _context.SponsorExhibitor
                                       join sponsor in _context.Sponsors on sponsorExhibitor.SponsorId equals sponsor.SponsorId
                                       join address in _context.Addresses on sponsor.AddressId equals address.AddressId into address1
                                       from address2 in address1.DefaultIfEmpty()
                                       join state in _context.States on address2.StateId equals state.StateId into state1
                                       from state2 in state1.DefaultIfEmpty()
                                       where sponsorExhibitor.IsActive == true && sponsorExhibitor.IsDeleted == false &&
                                       sponsor.IsActive == true && sponsor.IsDeleted == false &&
                                       sponsorExhibitor.ExhibitorId == exhibitorId
                                       select new GetSponsorsOfExhibitor
            {
                SponsorExhibitorId = sponsorExhibitor.SponsorExhibitorId,
                SponsorId = sponsor.SponsorId,
                Sponsor = sponsor.SponsorName,
                ContactName = sponsor.ContactName,
                Phone = sponsor.Phone,
                Address = address2 != null ? address2.Address:"",
                City = address2 != null ? address2.City:"",
                State = state2 != null? state2.Name:"",
                Zipcode = address2 != null? Convert.ToInt32(address2.ZipCode):0,
                Email = sponsor.Email,
                SponsorAmount = sponsorExhibitor.SponsorAmount,
                Amount = sponsor != null?Convert.ToDecimal(sponsor.AmountReceived):0,
                AmountPaid = 0,
                Balance = 0,
                SponsorTypeId = sponsorExhibitor.SponsorTypeId,
                HorseId = sponsorExhibitor.HorseId,
                HorseName = (from horse in _context.Horses where horse.HorseId == sponsorExhibitor.HorseId select horse.Name).FirstOrDefault(),
                SponsorTypeName = (from code in _context.GlobalCodes where code.GlobalCodeId == sponsorExhibitor.SponsorTypeId select code.CodeName).FirstOrDefault(),
                AdTypeName = (from fee in _context.YearlyMaintainenceFee where fee.YearlyMaintainenceFeeId == sponsorExhibitor.AdTypeId select fee.FeeName).FirstOrDefault(),
                IdNumber = sponsorExhibitor.SponsorTypeId == Convert.ToInt32(classSponsorTypeId) ? Convert.ToString(_context.Classes.Where(x => x.ClassId == Convert.ToInt32(sponsorExhibitor.TypeId)).Select(x => x.ClassNumber).FirstOrDefault())
                                               : Convert.ToString(sponsorExhibitor.TypeId),
            }).ToList();
            if (getSponsorsOfExhibitors.Count() != 0)
            {
                foreach (var item in getSponsorsOfExhibitors)
                {
                    var paidsponsorexhibitor    = Convert.ToDecimal(_context.SponsorExhibitor.Where(x => x.SponsorId == item.SponsorId && x.IsDeleted == false).Select(x => x.SponsorAmount).Sum());
                    var paidsponsornonexhibitor = Convert.ToDecimal(_context.SponsorDistributions.Where(x => x.SponsorId == item.SponsorId && x.IsDeleted == false).Select(x => x.TotalDistribute).Sum());
                    item.AmountPaid = paidsponsorexhibitor + paidsponsornonexhibitor;
                    item.Balance    = item.Amount - item.AmountPaid;

                    if (item.Balance < 0)
                    {
                        item.Balance = 0;
                    }
                    getSponsorsOfExhibitors1.Add(item);
                }
                getAllSponsorsOfExhibitor.getSponsorsOfExhibitors = getSponsorsOfExhibitors1;
                getAllSponsorsOfExhibitor.TotalRecords            = getSponsorsOfExhibitors.Count();
            }
            return(getAllSponsorsOfExhibitor);
        }