public IHttpActionResult PostEnrollmentOfficeConfig(EnrollmentAffiliateConfigDetailDTO oDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = _EnrollmentAffiliateConfigService.SaveEnrollmentAffiProgConfig(oDto);

            if (result == -1)
            {
                return(NotFound());
            }

            return(Ok(true));
        }
        /// <summary>
        /// This method is used to save and update the Enrollment Affiliate Configuration Detail
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public int SaveEnrollmentAffiProgConfig(EnrollmentAffiliateConfigDetailDTO dto)
        {
            //int entityState = 0;

            Guid refId = Guid.Empty, UserId, AffiliateProgId;

            bool IsUserId = Guid.TryParse(dto.UserId.ToString(), out UserId);

            if (!IsUserId)
            {
                return(-1);
            }

            if (dto != null)
            {
                // entityState = (int)System.Data.Entity.EntityState.Added;

                foreach (EnrollmentAffiliateConfigDTO item in dto.Affiliates)
                {
                    EnrollmentAffiliateConfiguration model = new EnrollmentAffiliateConfiguration();

                    if (item != null)
                    {
                        bool IsRefId = Guid.TryParse(item.CustomerId.ToString(), out refId);
                        if (!IsRefId)
                        {
                            return(-1);
                        }

                        bool IsAffiliateProgId = Guid.TryParse(item.AffiliateProgramId, out AffiliateProgId);
                        if (!IsAffiliateProgId)
                        {
                            return(-1);
                        }

                        decimal AffiliateProgramCharge;
                        bool    IsAffiliateProgramCharge = decimal.TryParse(item.AffiliateProgramCharge.ToString(), out AffiliateProgramCharge);
                        if (!IsAffiliateProgramCharge)
                        {
                            AffiliateProgramCharge = 0;
                        }

                        model.Id                     = Guid.NewGuid();
                        model.CustomerId             = refId;
                        model.AffiliateProgramId     = AffiliateProgId;
                        model.AffiliateProgramCharge = AffiliateProgramCharge;
                        model.StatusCode             = EMPConstants.Active;

                        model.LastUpdatedBy   = UserId;
                        model.LastUpdatedDate = System.DateTime.Now;
                        model.CreatedBy       = UserId;
                        model.CreatedDate     = System.DateTime.Now;

                        db.EnrollmentAffiliateConfigurations.Add(model);

                        //if (entityState == (int)System.Data.Entity.EntityState.Added)
                        //{
                        //    Guid SiteMapId;
                        //    Guid.TryParse("2f7d1b90-78aa-4a93-85ec-81cd8b10a545", out SiteMapId);
                        //    CustomerConfigurationStatu ConfigStatusModel = new CustomerConfigurationStatu();
                        //    ConfigStatusModel.Id = Guid.NewGuid();
                        //    ConfigStatusModel.CustomerId = dto.UserId ?? Guid.Empty;
                        //    ConfigStatusModel.SitemapId = SiteMapId;
                        //    ConfigStatusModel.StatusCode = "done";
                        //    ConfigStatusModel.UpdatedBy = dto.UserId ?? Guid.Empty;
                        //    ConfigStatusModel.UpdatedDate = DateTime.Now;
                        //    db.CustomerConfigurationStatus.Add(ConfigStatusModel);
                        //}
                    }
                }

                var _AffiliateList = db.EnrollmentAffiliateConfigurations.Where(a => a.CustomerId == refId).ToList();
                if (_AffiliateList.ToList().Count > 0)
                {
                    db.EnrollmentAffiliateConfigurations.RemoveRange(_AffiliateList);
                }
            }
            try
            {
                db.SaveChanges();
                db.Dispose();
                return(1);
            }
            catch (Exception ex)
            {
                EMPPortal.Core.Utilities.ExceptionLogger.LogException(ex.ToString(), "EnrollmentAffiliateConfigService/SaveEnrollmentAffiProgConfig", Guid.Empty);
                return(-1);

                throw;
            }
        }