コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }