예제 #1
0
        public MainResponse AddUpdateSponsorExhibitor(SponsorExhibitorRequest request)
        {
            if (request.SponsorExhibitorId <= 0)
            {
                decimal sponsorAmount = Convert.ToDecimal(_SponsorRepository.GetSingle(x => x.SponsorId == request.SponsorId).AmountReceived);

                decimal sponsorPaid = _SponsorExhibitorRepository.GetAll(x => x.SponsorId == request.SponsorId && x.IsDeleted == false).Select(x => x.SponsorAmount).Sum();

                decimal checkSponsorAmount = sponsorAmount - sponsorPaid;
                if (checkSponsorAmount <= 0)
                {
                    _mainResponse.Message = Constants.SPONSOR_NO_FUND;
                    _mainResponse.Success = false;
                    return(_mainResponse);
                }
                var checkexist = _SponsorExhibitorRepository.GetSingle(x => x.SponsorId == request.SponsorId && x.ExhibitorId == request.ExhibitorId &&
                                                                       x.IsActive == true && x.IsDeleted == false);
                if (checkexist != null && checkexist.SponsorExhibitorId > 0)
                {
                    _mainResponse.Message = Constants.RECORD_AlREADY_EXIST;
                    _mainResponse.Success = false;
                    return(_mainResponse);
                }
                var SponsorExhibitor = _Mapper.Map <SponsorExhibitor>(request);
                SponsorExhibitor.IsActive    = true;
                SponsorExhibitor.IsDeleted   = false;
                SponsorExhibitor.CreatedDate = DateTime.Now;
                _SponsorExhibitorRepository.Add(SponsorExhibitor);
                _mainResponse.Message = Constants.RECORD_ADDED_SUCCESS;
                _mainResponse.Success = true;
            }
            else
            {
                var SponsorExhibitor = _SponsorExhibitorRepository.GetSingle(x => x.SponsorExhibitorId == request.SponsorExhibitorId);
                if (SponsorExhibitor != null && SponsorExhibitor.SponsorExhibitorId > 0)
                {
                    SponsorExhibitor.SponsorId     = request.SponsorId;
                    SponsorExhibitor.ExhibitorId   = request.ExhibitorId;
                    SponsorExhibitor.SponsorTypeId = request.SponsorTypeId;
                    SponsorExhibitor.SponsorAmount = request.SponsorAmount;
                    SponsorExhibitor.HorseId       = request.HorseId;
                    SponsorExhibitor.AdTypeId      = Convert.ToInt32(request.AdTypeId);
                    SponsorExhibitor.TypeId        = request.TypeId;
                    SponsorExhibitor.ModifiedDate  = DateTime.Now;
                    _SponsorExhibitorRepository.Update(SponsorExhibitor);
                    _mainResponse.Message = Constants.RECORD_UPDATE_SUCCESS;
                    _mainResponse.Success = true;
                }
                else
                {
                    _mainResponse.Message = Constants.NO_RECORD_EXIST_WITH_ID;
                    _mainResponse.Success = false;
                }
            }
            return(_mainResponse);
        }
예제 #2
0
        public MainResponse AddUpdateSponsor(SponsorRequest request)
        {
            if (request.SponsorId == null || request.SponsorId <= 0)
            {
                var checkexist = _SponsorRepository.GetSingle(x => x.SponsorName == request.SponsorName &&
                                                              x.IsActive == true && x.IsDeleted == false);
                if (checkexist != null && checkexist.SponsorId > 0)
                {
                    _mainResponse.Message = Constants.NAME_ALREADY_EXIST;
                    _mainResponse.Success = false;
                    return(_mainResponse);
                }

                var addressEntity = new Addresses
                {
                    Address     = request.Address,
                    StateId     = request.StateId,
                    City        = request.City,
                    ZipCode     = request.ZipCode,
                    CreatedDate = DateTime.Now,
                    IsActive    = true,
                    IsDeleted   = false
                };
                var address = _AddressRepository.Add(addressEntity);
                var sponsor = new Sponsors
                {
                    SponsorName    = request.SponsorName,
                    ContactName    = request.ContactName,
                    Phone          = request.Phone,
                    Email          = request.Email,
                    AmountReceived = request.AmountReceived,
                    AddressId      = address != null? address.AddressId:0,
                    CreatedDate    = DateTime.Now,
                    IsActive       = true,
                    IsDeleted      = false
                };
                var Data = _SponsorRepository.Add(sponsor);
                _mainResponse.Message      = Constants.RECORD_ADDED_SUCCESS;
                _mainResponse.Success      = true;
                _mainResponse.NewId        = Data.SponsorId;
                newIdResponse.NewId        = Data.SponsorId;
                _mainResponse.BaseResponse = newIdResponse;
            }
            else
            {
                var sponsor = _SponsorRepository.GetSingle(x => x.SponsorId == request.SponsorId && x.IsActive == true && x.IsDeleted == false);
                if (sponsor != null && sponsor.SponsorId > 0)
                {
                    sponsor.SponsorName    = request.SponsorName;
                    sponsor.ContactName    = request.ContactName;
                    sponsor.Phone          = request.Phone;
                    sponsor.Email          = request.Email;
                    sponsor.AmountReceived = request.AmountReceived;
                    sponsor.ModifiedDate   = DateTime.Now;
                    _SponsorRepository.Update(sponsor);

                    var address = _AddressRepository.GetSingle(x => x.AddressId == sponsor.AddressId && x.IsActive == true && x.IsDeleted == false);
                    if (address != null && address.AddressId > 0)
                    {
                        address.Address      = request.Address;
                        address.StateId      = request.StateId;
                        address.City         = request.City;
                        address.ZipCode      = request.ZipCode;
                        address.ModifiedDate = DateTime.Now;
                        _AddressRepository.Update(address);
                    }
                    _mainResponse.Message      = Constants.RECORD_UPDATE_SUCCESS;
                    _mainResponse.Success      = true;
                    _mainResponse.NewId        = Convert.ToInt32(request.SponsorId);
                    newIdResponse.NewId        = Convert.ToInt32(request.SponsorId);
                    _mainResponse.BaseResponse = newIdResponse;
                }
                else
                {
                    _mainResponse.Message = Constants.NO_RECORD_EXIST_WITH_ID;
                    _mainResponse.Success = false;
                }
            }
            return(_mainResponse);
        }
        public MainResponse AddUpdateSponsorDistribution(SponsorDistributionRequest request)
        {
            int idNumber = 0;

            Int32.TryParse(request.TypeId, out idNumber);
            if (idNumber <= 0)
            {
                _mainResponse.Message = Constants.INVALID_ID_NUMBER;
                _mainResponse.Success = false;
                return(_mainResponse);
            }
            var sponsortypes = _GlobalCodeRepository.GetCodes("SponsorTypes");

            var classsponsortype = sponsortypes.globalCodeResponse.Where(x => x.CodeName == "Class").FirstOrDefault();

            if (request.SponsorDistributionId <= 0)
            {
                decimal sponsorAmount = Convert.ToDecimal(_SponsorRepository.GetSingle(x => x.SponsorId == request.SponsorId).AmountReceived);

                decimal sponsorexhibitorPaid    = _SponsorExhibitorRepository.GetAll(x => x.SponsorId == request.SponsorId && x.IsDeleted == false).Select(x => x.SponsorAmount).Sum();
                decimal sponsordistributionPaid = _SponsorDistributionRepository.GetAll(x => x.SponsorId == request.SponsorId && x.IsDeleted == false).Select(x => x.TotalDistribute).Sum();

                decimal checkSponsorAmount = sponsorAmount - (sponsorexhibitorPaid + sponsordistributionPaid);
                if (checkSponsorAmount <= 0)
                {
                    _mainResponse.Message = Constants.SPONSOR_NO_FUND;
                    _mainResponse.Success = false;
                    return(_mainResponse);
                }
                decimal checkAddedAmount = checkSponsorAmount - request.TotalDistribute;
                if (checkAddedAmount < 0)
                {
                    _mainResponse.Message = Constants.SPONSOR_NO_FUND;
                    _mainResponse.Success = false;
                    return(_mainResponse);
                }
                var sponsorType = _GlobalCodeRepository.GetSingle(x => x.GlobalCodeId == request.SponsorTypeId);

                if (sponsorType.CodeName == "Ad" || sponsorType.CodeName == "Cooler" || sponsorType.CodeName == "Patron")
                {
                    var sponsorAdExist = _SponsorDistributionRepository.GetSingle(x => x.TypeId == Convert.ToString(idNumber) &&
                                                                                  x.SponsorTypeId != classsponsortype.GlobalCodeId && x.IsDeleted == false);



                    if (sponsorAdExist != null)
                    {
                        _mainResponse.Message = Constants.AD_NUMBER_EXIST;
                        _mainResponse.Success = false;
                        return(_mainResponse);
                    }
                }
                request.TypeId = Convert.ToString(idNumber);
                var sponsorDistribution = _Mapper.Map <SponsorDistributions>(request);
                sponsorDistribution.IsActive    = true;
                sponsorDistribution.IsDeleted   = false;
                sponsorDistribution.CreatedDate = DateTime.Now;
                _SponsorDistributionRepository.Add(sponsorDistribution);
                _mainResponse.Message = Constants.RECORD_ADDED_SUCCESS;
                _mainResponse.Success = true;
            }
            else
            {
                var sponsorDistribution = _SponsorDistributionRepository.GetSingle(x => x.SponsorDistributionId == request.SponsorDistributionId);
                if (sponsorDistribution != null && sponsorDistribution.SponsorDistributionId > 0)
                {
                    sponsorDistribution.SponsorId       = request.SponsorId;
                    sponsorDistribution.SponsorTypeId   = request.SponsorTypeId;
                    sponsorDistribution.TotalDistribute = request.TotalDistribute;
                    sponsorDistribution.AdTypeId        = Convert.ToInt32(request.AdTypeId);
                    sponsorDistribution.TypeId          = request.TypeId;
                    sponsorDistribution.ModifiedDate    = DateTime.Now;

                    _SponsorDistributionRepository.Update(sponsorDistribution);
                    _mainResponse.Message = Constants.RECORD_UPDATE_SUCCESS;
                    _mainResponse.Success = true;
                }
                else
                {
                    _mainResponse.Message = Constants.NO_RECORD_EXIST_WITH_ID;
                    _mainResponse.Success = false;
                }
            }
            return(_mainResponse);
        }