public async Task <IActionResult> Post([FromBody] DDLCatalogDto catalogDto) { if (ModelState.IsValid) { var item = await _catalogService.AddOrUpdateAsync(catalogDto); return(Ok(item)); } return(NoContent()); }
public async Task <DDLCatalogDto> GetByIdAsync(string id) { DDLCatalogDto itemDto = null; try { var item = await _dDLCatalogRepository.FindEntityBy(x => x.Id == id); itemDto = _mapper.Map <DDLCatalogDto>(item); } catch (Exception ex) { LoggerService.LogToFile(ex); } return(itemDto); }
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); }