public InsuranceBenefitType Create(InsuranceBenefitType item)
        {
            String exception = string.Empty;

            // validation
            //if (item.LoginProviderId == 0)
            //    throw new AppException("LoginProviderId is required");

            //if (!_context.LoginProvider.Any(lp => lp.Id == item.LoginProviderId && lp.DelFlag == false))
            //    throw new AppException("LoginProviderId is invalid");

            //if (string.IsNullOrWhiteSpace(password) && item.LoginProviderId == (int)LoginProviderEnum.Local)
            //    throw new AppException("Password is required");

            //if (string.IsNullOrWhiteSpace(item.UserName))
            //    throw new AppException("UserName is required");

            if (!ValidateRequireField(item, out exception))
            {
                throw new AppException(exception);
            }

            if (_context.InsuranceBenefitType.Any(x => x.BenefitType == item.BenefitType))
            {
                throw new AppException("Benefit Type Name" + item.BenefitType + " is already exists");
            }


            item.CreatedAt = DateTime.Now;
            item.UpdatedAt = DateTime.Now;
            _context.InsuranceBenefitType.Add(item);
            _context.SaveChanges();

            return(item);
        }
        private Boolean ValidateRequireField(InsuranceBenefitType item, out String exception)
        {
            exception = string.Empty;

            // validation
            if (string.IsNullOrWhiteSpace(item.BenefitType))
            {
                exception = "Cover Name is required";
                return(false);
                //throw new AppException("LoginProviderId is required");
            }


            return(true);
        }
        public InsuranceBenefitType GetById(int id)
        {
            InsuranceBenefitType item = null;

            try
            {
                item = _context.InsuranceBenefitType.Where(u => u.Id == id).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(item);
        }
        public void Delete(InsuranceBenefitType item)
        {
            var _InsuranceBenefitType = _context.InsuranceBenefitType.Find(item.Id);

            if (_InsuranceBenefitType != null)
            {
                _InsuranceBenefitType.DeletedAt = DateTime.Now;
                _InsuranceBenefitType.UpdatedAt = DateTime.Now;

                _context.InsuranceBenefitType.Update(_InsuranceBenefitType);
                _context.SaveChanges();
            }
            else
            {
                throw new AppException("Cover not found");
            }
        }
        public InsuranceBenefitType Update(InsuranceBenefitType item)
        {
            String exception = string.Empty;

            var _InsuranceBenefitType = _context.InsuranceBenefitType.Find(item.Id);


            if (_InsuranceBenefitType == null)
            {
                throw new AppException("Cover not found");
            }

            // validation
            if (!ValidateRequireField(item, out exception))
            {
                throw new AppException(exception);
            }

            if (item.BenefitType.ToLower() != _InsuranceBenefitType.BenefitType.ToLower())
            {
                // Cover Name has changed so check if the new Cover Name is already exists
                if (_context.InsuranceBenefitType.Any(x => x.BenefitType == item.BenefitType))
                {
                    throw new AppException("Benefit Type Name " + item.BenefitType + " is already exists");
                }
            }

            _InsuranceBenefitType.BenefitType         = item.BenefitType;
            _InsuranceBenefitType.ParentBenefitTypeID = item.ParentBenefitTypeID;
            _InsuranceBenefitType.RowOrder            = item.RowOrder;
            _InsuranceBenefitType.DeletedAt           = item.DeletedAt;
            _InsuranceBenefitType.UpdatedAt           = DateTime.Now;

            _context.InsuranceBenefitType.Update(_InsuranceBenefitType);
            _context.SaveChanges();

            return(item);
        }