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);
        }
예제 #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);
        }