Exemplo n.º 1
0
        public BaseSingleResponse <CfgProvideHelpPolicyDto> Add(CfgProvideHelpPolicyDto dto)
        {
            var response = new BaseSingleResponse <CfgProvideHelpPolicyDto>();

            try
            {
                var errors = Validate <CfgProvideHelpPolicyDto>(dto, new CfgProvideHelpPolicyValidator());
                if (errors.Count() > 0)
                {
                    return(new BaseSingleResponse <CfgProvideHelpPolicyDto>(dto, errors));
                }

                var policy = new CfgProvideHelpPolicy();

                policy.Name        = dto.Name;
                policy.Description = dto.Description;

                policy.ProfitRate   = double.Parse(dto.ProfitRateTemp);
                policy.NumberOfDays = int.Parse(dto.NumberOfDaysTemp);
                policy.CreatedDate  = DateTime.Now;
                policy.ModifiedDate = policy.CreatedDate;
                policy.Status       = (int)CfgProvideHelpPolicyStatusEnum.ENABLE;

                _repository.Add(policy);
                _repository.SubmitChanges();
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
            }

            return(response);
        }
Exemplo n.º 2
0
        public BaseSingleResponse <CfgProvideHelpPolicyDto> GetById(long id)
        {
            var response = new BaseSingleResponse <CfgProvideHelpPolicyDto>();

            try
            {
                CfgProvideHelpPolicy policy = SingleById(id);
                if (policy != null)
                {
                    CfgProvideHelpPolicyDto dto = MapperUtils.ConvertTo <CfgProvideHelpPolicy, CfgProvideHelpPolicyDto>(policy);
                    dto.NumberOfDaysTemp = policy.NumberOfDays.ToString();
                    dto.ProfitRateTemp   = policy.ProfitRate.ToString();

                    response.Value = dto;
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
            }
            return(response);
        }