public async Task <IActionResult> CreateTemplate([FromBody] CreateTemplateCommand command) { try { string orgEmail = JwtClaim.GetEmail(User); UserTemplateDTO createdTemplate = await this._service.Create(orgEmail, command); return(Created("template/", createdTemplate._tid)); } catch (Exception e) { this._logger.LogError(e, e.Message); return(StatusCode(500)); } }
public async Task <IActionResult> GetTemplateById(string id) { try { UserTemplateDTO template = await this._service.GetById(Guid.Parse(id)); if (template == null) { return(NotFound(new Error(String.Format("The template with ID {0} does not exist", id)))); } return(Ok(template)); } catch (Exception e) { this._logger.LogError(e, e.Message); return(StatusCode(500)); } }
public async Task <UserTemplateDTO> Create(string email, CreateTemplateCommand command) { try { Organization org = await this._orgService.GetByEmail(email); UserTemplate template = new UserTemplate(org, command.attributes); UserTemplate createdTemplate = await this._repo.Create(template); org.associateTemplate(createdTemplate); await this._orgService.Update(org); UserTemplateDTO dto = new UserTemplateDTO(createdTemplate._tid, createdTemplate.attributes); return(dto); } catch (Exception) { throw new Exception("Internal error creating a User Template"); } }
public async Task <UserTemplateDTO> Delete(Guid id) { try { UserTemplate template = await this._repo.GetById(id); if (template == null) { return(null); } await this._repo.Delete(template); UserTemplateDTO dto = new UserTemplateDTO(template._tid, template.attributes); return(dto); } catch (System.Exception) { throw new Exception("Internal error deleting an existing User Template"); } }
public async Task <UserTemplateDTO> GetById(Guid id) { try { UserTemplate template = await this._repo.GetById(id); if (template != null) { UserTemplateDTO dto = new UserTemplateDTO(template._tid, template.attributes); return(dto); } else { return(null); } } catch (Exception) { throw new Exception("Internal error fetching a User Template"); } }