public async Task <BaseResponse> DeleteDetailAsync(string id)
        {
            var response = new BaseResponse();

            try
            {
                var item = await _formDetailRepository.FindEntityBy(x => x.Id == id);

                if (item == null)
                {
                    response.Message = LoggingEvents.UPDATE_FAILED_MESSAGE;
                    return(response);
                }

                item.IsActive = false;
                _formDetailRepository.Edit(item);
                await _formDetailRepository.SaveChanges();

                response.Success = true;
                response.Id      = id;
                response.Message = LoggingEvents.UPDATE_SUCCESS_MESSAGE;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.UPDATE_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
        public async Task <BaseResponse> UpdateFormHdFileAsync(string id, string fileName)
        {
            var response = new BaseResponse();

            try
            {
                var item = await _formHdRepository.FindEntityBy(x => x.Id == id);

                if (item == null)
                {
                    response.Message = LoggingEvents.UPDATE_FAILED_MESSAGE;
                    return(response);
                }

                item.FilePath = fileName;
                _formHdRepository.Edit(item);
                await _formHdRepository.SaveChanges();

                response.Success = true;
                response.Id      = id;
                response.Message = LoggingEvents.DELETE_SUCCESS_MESSAGE;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.DELETE_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
        public async Task <IEnumerable <FormHdDto> > GetAllAsync()
        {
            var listDto = new List <FormHdDto>();

            try
            {
                var list = await _formHdRepository.GetAll(t => t.FormDetails);

                foreach (var item in list)
                {
                    item.FormDetails = item.FormDetails.OrderBy(x => x.Order).ToList();
                    var landingPage = await _landingPageRepository.FindBy(x => x.FormHdId == item.Id);

                    item.LandingPages = landingPage.ToList();
                    foreach (var detail in item.FormDetails.Where(x => x.FieldTypeId == FieldType.select.ToString()))
                    {
                        var ddlCatalogs = await _dDLCatalogRepository.FindBy(x => x.FormDetailId == detail.Id);

                        detail.DDLCatalogs = ddlCatalogs.ToList();
                    }
                }

                listDto = _mapper.Map <List <FormHdDto> >(list);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <BaseResponse> DeleteAsync(string id)
        {
            var response = new BaseResponse();

            try
            {
                var item = await _infoRequestRepository.FindEntityBy(x => x.Id == id);

                if (item == null)
                {
                    response.Message = LoggingEvents.DELETE_FAILED_MESSAGE;
                    return(response);
                }

                _infoRequestRepository.Delete(item);
                await _infoRequestRepository.SaveChanges();

                response.Success = true;
                response.Message = LoggingEvents.DELETE_SUCCESS_MESSAGE;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
        private async Task SendMailToClient(string emailTo, string name, string attach, string mailTemplateId)
        {
            var attachs = new List <string>();

            if (!string.IsNullOrEmpty(attach))
            {
                attachs.Add(attach);
            }
            ;
            name = name ?? emailTo;

            var mailTemplate = await _mailTemplateService.GetByIdAsync(mailTemplateId);

            var subject = "Mensaje de notificación";
            var message = $"<div><p>Hola {name}</p><p>¡Gracias por tu interés en Grupo PerTI!</p><p></p>Nos pondremos en contacto contigo lo más pronto posible.<div>";

            if (mailTemplate != null)
            {
                subject = mailTemplate.Subject;
                message = SetTemplate(mailTemplate, name, true);
            }

            try
            {
                await _emailSenderService.SendEmailAsync(emailTo, subject, message, attachs);
            }
            catch (Exception ex)
            {
                LoggerService.LogToFile(ex);
            }
        }
        public async Task <FormHdDto> GetByIdAsync(string id)
        {
            FormHdDto itemDto = null;

            try
            {
                var item = await _formHdRepository.FindEntityBy(x => x.Id == id, t => t.FormDetails);

                if (item != null)
                {
                    item.FormDetails = item.FormDetails.OrderBy(x => x.Order).ToList();
                    foreach (var detail in item.FormDetails.Where(x => x.FieldTypeId == FieldType.select.ToString()))
                    {
                        var ddlCatalogs = await _dDLCatalogRepository.FindBy(x => x.FormDetailId == detail.Id);

                        detail.DDLCatalogs = ddlCatalogs.ToList();
                    }
                }

                _mapper.Map <FormHdDto>(item);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(itemDto);
        }
        public async Task <IEnumerable <InfoRequestDto> > GetByAsync(BaseRequest request)
        {
            var listDto = new List <InfoRequestDto>();

            try
            {
                //DateTime startDate = DateTime.MinValue ;
                //if (request.StartDate.HasValue)
                //{
                //    DateTime.TryParse(request.StartDate.Value.ToString("yyyy-MM-dd"), out startDate);
                //}
                //DateTime endDate = DateTime.MinValue;
                //if (request.EndDate.HasValue)
                //{
                //    DateTime.TryParse(request.StartDate.Value.ToString("yyyy-MM-dd"), out endDate);
                //}

                var list = await _infoRequestRepository.FindBy(x => x.IsActive, x => x.LandingPage);

                if (!string.IsNullOrEmpty(request.LandingPageId))
                {
                    list = list.Where(x => x.LandingPageId == request.LandingPageId);
                }

                if (request.StartDate.HasValue && request.EndDate.HasValue)
                {
                    var endDate = request.EndDate.Value.Date.AddDays(1);
                    list = list.Where(x => x.RequestDate.Date >= request.StartDate.Value.Date && x.RequestDate <= endDate.Date);
                }
                else
                {
                    if (request.StartDate.HasValue)
                    {
                        list = list.Where(x => x.RequestShortDate.Date >= request.StartDate.Value.Date);
                    }
                    else if (request.EndDate.HasValue)
                    {
                        list = list.Where(x => x.RequestDate.Date <= request.EndDate.Value.Date);
                    }
                    else
                    {
                        var end   = DateTime.Now;
                        var start = end.AddDays(-15);
                        list = list.Where(x => x.RequestDate.Date >= start.Date && x.RequestDate.Date <= end.Date);
                    }
                }

                listDto = _mapper.Map <List <InfoRequestDto> >(list);
            }
            catch (Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <BaseResponse> AddOrUpdateAsync(LandingPageDto landingPageDto, string userName)
        {
            var response = new BaseResponse();

            try
            {
                //mappear el DTO
                var landingPage = _mapper.Map <LandingPage>(landingPageDto);
                _landingPageRepository.UserName = userName;
                if (string.IsNullOrEmpty(landingPage.Id))
                {
                    //validar el nombre del landing page
                    var landing = await _landingPageRepository.FindEntityBy(x => x.Name.Trim().ToLower() == landingPageDto.Name.Trim().ToLower());

                    if (landing != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }


                    landingPage.Id = Common.Utilities.Utils.NewGuid;
                    _landingPageRepository.Add(landingPage);
                    response.Message = LoggingEvents.INSERT_SUCCESS_MESSAGE;
                }
                else
                {
                    //validar el nombre del template page
                    var landing = await _landingPageRepository.FindEntityBy(x => x.Name.Trim().ToLower() == landingPageDto.Name.Trim().ToLower() && x.Id != landingPageDto.Id);

                    if (landing != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }

                    landingPage.FormHdId = (string.IsNullOrEmpty(landingPage.FormHdId)) ? null : landingPage.FormHdId;
                    _landingPageRepository.Edit(landingPage);
                    response.Message = LoggingEvents.UPDATE_SUCCESS_MESSAGE;
                }

                var item = await _landingPageRepository.SaveChanges();

                response.Success = true;
                response.Id      = landingPage.Id;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
        public async Task <BaseResponse> AddOrUpdateAsync(MailTemplateDto mailTemplateDto, string userName)
        {
            var response = new BaseResponse();

            try
            {
                _mailTemplateRepository.UserName = userName;
                var mailTemplate = _mapper.Map <MailTemplate>(mailTemplateDto);
                if (string.IsNullOrEmpty(mailTemplate.Id))
                {
                    //validar el nombre del template page
                    var template = await _mailTemplateRepository.FindEntityBy(x => x.Name.Trim().ToLower() == mailTemplateDto.Name.Trim().ToLower());

                    if (template != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }


                    mailTemplate.Id       = Common.Utilities.Utils.NewGuid;
                    mailTemplate.IsActive = true;
                    _mailTemplateRepository.Add(mailTemplate);
                    response.Message = LoggingEvents.INSERT_SUCCESS_MESSAGE;
                }
                else
                {
                    //validar el nombre del template page
                    var template = await _mailTemplateRepository.FindEntityBy(x => x.Name.Trim().ToLower() == mailTemplateDto.Name.Trim().ToLower() && x.Id != mailTemplateDto.Id);

                    if (template != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }

                    _mailTemplateRepository.Edit(mailTemplate);
                    response.Message = LoggingEvents.UPDATE_SUCCESS_MESSAGE;
                }

                var item = await _mailTemplateRepository.SaveChanges();

                response.Success = true;
                response.Id      = mailTemplate.Id;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
        public async Task <FormDetailDto> GetDetailByIdAsync(string id)
        {
            FormDetailDto itemDto = null;

            try
            {
                var item = await _formDetailRepository.FindEntityBy(x => x.Id == id);

                itemDto = _mapper.Map <FormDetailDto>(item);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(itemDto);
        }
        public async Task <IEnumerable <FormDetailDto> > GetDetailAllAsync(string formHdId)
        {
            var listDto = new List <FormDetailDto>();

            try
            {
                var list = await _formDetailRepository.FindBy(x => x.FormHdId == formHdId);

                listDto = _mapper.Map <List <FormDetailDto> >(list);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <IEnumerable <FormHdDto> > GetAllForOptionsAsync()
        {
            var listDto = new List <FormHdDto>();

            try
            {
                var list = await _formHdRepository.FindBy(x => x.IsActive);

                listDto = _mapper.Map <List <FormHdDto> >(list);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <MailTemplateDto> GetByIdAsync(string id)
        {
            MailTemplateDto itemDto = null;

            try
            {
                var item = await _mailTemplateRepository.FindEntityAsNoTrackingBy(x => x.Id == id);

                itemDto = _mapper.Map <MailTemplateDto>(item);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(itemDto);
        }
        public async Task <IEnumerable <InfoRequestDto> > GetAllAsync()
        {
            var listDto = new List <InfoRequestDto>();

            try
            {
                var list = await _infoRequestRepository.GetAll();

                listDto = _mapper.Map <List <InfoRequestDto> >(list);
            }
            catch (Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <InfoRequestDto> GetByIdAsync(string id)
        {
            InfoRequestDto itemDto = null;

            try
            {
                var item = await _infoRequestRepository.FindEntityBy(x => x.Id == id);

                itemDto = _mapper.Map <InfoRequestDto>(item);
            }
            catch (Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(itemDto);
        }
        public async Task <IEnumerable <KeyValuePair <string, string> > > GetAllforDDL()
        {
            var listDto = new List <KeyValuePair <string, string> >();

            try
            {
                var list = await _landingPageRepository.FindBy(x => x.IsActive);

                listDto = list.Select(x => new KeyValuePair <string, string>(x.Id, x.Name)).ToList();
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <LandingPageDto> GetByIdAsync(string id)
        {
            LandingPageDto itemDto = null;

            try
            {
                var item = await _landingPageRepository.FindEntityBy(x => x.Id == id);

                itemDto = _mapper.Map <LandingPageDto>(item);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(itemDto);
        }
        public async Task <IEnumerable <LandingPageDto> > GetAllAsync()
        {
            var listDto = new List <LandingPageDto>();

            try
            {
                var list = await _landingPageRepository.GetAll();

                listDto = _mapper.Map <List <LandingPageDto> >(list);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <BaseResponse> AddOrUpdateDetailAsync(FormDetailDto formDetailDto)
        {
            var response = new BaseResponse();

            try
            {
                var formDetail = _mapper.Map <FormDetail>(formDetailDto);
                if (string.IsNullOrEmpty(formDetail.Id))
                {
                    formDetail.Id       = Common.Utilities.Utils.NewGuid;
                    formDetail.IsActive = true;
                    _formDetailRepository.Add(formDetail);
                    response.Message = LoggingEvents.INSERT_SUCCESS_MESSAGE;
                }
                else
                {
                    formDetail = await _formDetailRepository.FindEntityBy(x => x.Id == formDetailDto.Id);

                    if (formDetail != null)
                    {
                        formDetail.FieldLabel = formDetailDto.FieldLabel;
                        formDetail.Order      = formDetailDto.Order;
                        _formDetailRepository.Edit(formDetail);
                    }
                    else
                    {
                        response.Message = LoggingEvents.UPDATE_FAILED_MESSAGE;
                        return(response);
                    }
                    response.Message = LoggingEvents.UPDATE_SUCCESS_MESSAGE;
                }

                var item = await _formDetailRepository.SaveChanges();

                response.Success = true;
                response.Id      = formDetail.Id;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
示例#20
0
        public async Task <BaseResponse> AddOrUpdateAsync(DDLCatalogDto catalogDto)
        {
            var response = new BaseResponse();

            try
            {
                var catalog = _mapper.Map <DDLCatalog>(catalogDto);
                if (string.IsNullOrEmpty(catalog.Id))
                {
                    //validar el nombre del landing page
                    var ecatalog = await _dDLCatalogRepository
                                   .FindEntityBy(x => x.FormDetailId == catalogDto.FormDetailId &&
                                                 x.Name.Trim().ToLower() == catalogDto.Name.Trim().ToLower());

                    if (ecatalog != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }

                    catalog.Id       = Common.Utilities.Utils.NewGuid;
                    catalog.IsActive = true;
                    _dDLCatalogRepository.Add(catalog);
                    response.Message = LoggingEvents.INSERT_SUCCESS_MESSAGE;
                }
                else
                {
                    _dDLCatalogRepository.Edit(catalog);
                    response.Message = LoggingEvents.UPDATE_SUCCESS_MESSAGE;
                }

                await _dDLCatalogRepository.SaveChanges();

                response.Success = true;
                response.Id      = catalog.Id;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
示例#21
0
        public async Task <IEnumerable <DDLCatalogDto> > GetAllAsync()
        {
            var listDto = new List <DDLCatalogDto>();

            try
            {
                var list = await _dDLCatalogRepository.GetAll();

                listDto = _mapper.Map <List <DDLCatalogDto> >(list);
            }
            catch (Exception ex)
            {
                LoggerService.LogToFile(ex);
                throw ex;
            }

            return(listDto);
        }
        public async Task <IEnumerable <LandingPageDto> > GetAllOptionsAsync()
        {
            var listDto = new List <LandingPageDto>();

            try
            {
                var list = await _landingPageRepository.FindBy(x => x.IsActive);

                list    = list.Where(x => string.IsNullOrEmpty(x.FormHdId)).ToList();
                listDto = _mapper.Map <List <LandingPageDto> >(list);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(listDto);
        }
        public async Task <IEnumerable <BaseDetailSettings> > GetBaseDetail()
        {
            var list = new List <BaseDetailSettings>();

            try
            {
                await Task.Run(() =>
                {
                    list = _baseDetailSettings.Value.ToList();
                });
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(list);
        }
        public async Task <BaseResponse> AddAsync(InfoRequestDto infoRequestDto)
        {
            var response = new BaseResponse();

            try
            {
                var infoRequest = _mapper.Map <InfoRequest>(infoRequestDto);
                if (string.IsNullOrEmpty(infoRequest.Id))
                {
                    infoRequest.Id          = Common.Utilities.Utils.NewGuid;
                    infoRequest.IsActive    = true;
                    infoRequest.RequestDate = DateTime.UtcNow;
                    _infoRequestRepository.Add(infoRequest);

                    var item = await _infoRequestRepository.SaveChanges();

                    var attach = string.Empty;
                    if (!string.IsNullOrEmpty(infoRequestDto.FileName))
                    {
                        var baseDir = _appSettings?.Value?.EbookPath ?? string.Empty;
                        attach = Path.Combine(baseDir, infoRequestDto.FormHdId, infoRequestDto.FileName);
                    }

                    await SendMailToClient(infoRequestDto.Email, infoRequestDto.Name, attach, infoRequestDto.MailTemplateId);

                    response.Success = true;
                    response.Id      = infoRequest.Id;
                    response.Message = LoggingEvents.INSERT_SUCCESS_MESSAGE;
                }
                else
                {
                    response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                }
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }
        public async Task <FormHdDto> GetByLandingPageIdAsync(string landingPageId)
        {
            FormHdDto itemDto = null;

            try
            {
                var landings = await _landingPageRepository.FindBy(x => x.Id == landingPageId && x.IsActive);

                if (landings.Count() == 0)
                {
                    return(itemDto);
                }

                var formHdId = landings.FirstOrDefault().FormHdId;
                var item     = await _formHdRepository.FindEntityBy(x => x.Id == formHdId, t => t.FormDetails);

                if (item != null)
                {
                    item.FormDetails = item.FormDetails.Where(x => x.IsActive).OrderBy(x => x.Order).ToList();
                    foreach (var detail in item.FormDetails.Where(x => x.FieldTypeId == FieldType.select.ToString()))
                    {
                        var ddlCatalogs = await _dDLCatalogRepository.FindBy(x => x.FormDetailId == detail.Id);

                        detail.DDLCatalogs = ddlCatalogs.ToList();
                    }
                }

                itemDto = _mapper.Map <FormHdDto>(item);
            }
            catch (System.Exception ex)
            {
                LoggerService.LogToFile(ex);
            }

            return(itemDto);
        }
        public async Task <BaseResponse> AddOrUpdateAsync(FormHdDto formHdDto, string userName)
        {
            var response = new BaseResponse();

            try
            {
                var formHd = _mapper.Map <FormHd>(formHdDto);
                if (string.IsNullOrEmpty(formHd.Id))
                {
                    //validar el nombre del form
                    var form = await _formHdRepository.FindEntityBy(x => x.Name.Trim().ToLower() == formHdDto.Name.Trim().ToLower());

                    if (form != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }

                    formHd.Id = Common.Utilities.Utils.NewGuid;
                    _formHdRepository.UserName = userName;
                    _formHdRepository.Add(formHd);


                    foreach (var page in formHdDto.LandingPages)
                    {
                        var landing = await _landingPageRepository.FindEntityBy(x => x.Id == page.Id);

                        if (landing != null)
                        {
                            if (landing.FormHdId != null)
                            {
                                response.Message = $"El landing page: { landing.Name } ya cuenta con un formulario asignado, es recomendable darle de baja antes";
                            }
                            else
                            {
                                landing.FormHdId = formHd.Id;
                                _landingPageRepository.UserName = userName;
                                _landingPageRepository.Edit(landing);
                            }
                        }
                    }


                    foreach (var detail in formHd.FormDetails)
                    {
                        if (detail.DDLCatalogs != null && detail.DDLCatalogs.Count > 0)
                        {
                            foreach (var cat in detail.DDLCatalogs)
                            {
                                cat.IsActive     = true;
                                cat.FormDetailId = detail.Id;
                                _dDLCatalogRepository.UserName = userName;
                                _dDLCatalogRepository.Add(cat);
                            }
                        }
                    }

                    response.Message = LoggingEvents.INSERT_SUCCESS_MESSAGE;
                }
                else
                {
                    //validar el nombre del form
                    var form = await _formHdRepository.FindEntityBy(x => x.Name.Trim().ToLower() == formHdDto.Name.Trim().ToLower() && x.Id != formHdDto.Id);

                    if (form != null)
                    {
                        response.Message = LoggingEvents.INSERT_DUPLICATED_MESSAGE;
                        return(response);
                    }

                    foreach (var page in formHdDto.LandingPages)
                    {
                        var landing = await _landingPageRepository.FindEntityBy(x => x.Id == page.Id);

                        if (landing != null)
                        {
                            if (landing.FormHdId != null)
                            {
                                response.Message = $"El landing page: { landing.Name } ya cuenta con un formulario asignado, es recomendable darle de baja antes";
                            }
                            else
                            {
                                landing.FormHdId = formHd.Id;
                                _landingPageRepository.UserName = userName;
                                _landingPageRepository.Edit(landing);
                            }
                        }
                    }


                    foreach (var detalleDto in formHd.FormDetails)
                    {
                        _formDetailRepository.Edit(detalleDto);
                    }


                    _formHdRepository.UserName = userName;
                    _formHdRepository.Edit(formHd);
                    response.Message = LoggingEvents.UPDATE_SUCCESS_MESSAGE;
                }


                var item = await _formHdRepository.SaveChanges();

                response.Success = true;
                response.Id      = formHd.Id;
            }
            catch (System.Exception ex)
            {
                response.Message = LoggingEvents.INSERT_FAILED_MESSAGE;
                LoggerService.LogToFile(ex);
            }

            return(response);
        }