public static EventEntity MakeEventEntity(CreateCompanyCmd cmd) { return(new EventEntity { UserId = cmd.UserId, Body = new CompanyCreatedEvt(cmd) }); }
public async Task <IActionResult> Create([FromBody] CreateCompanyReq req) { var cmd = new CreateCompanyCmd(req, HttpContext.UserId().Value); var company = await companyRepo.Create(cmd); return(Created($"/api/companies/${company.Id}", new CompanyResult(company))); }
public CompanyCreatedEvt(CreateCompanyCmd cmd) { Name = cmd.Name; Activity = cmd.Activity; Url = cmd.Url; ParentId = cmd.ParentId; Color = cmd.Color; Modules = cmd.Modules; }
public async Task <CompanyEntity> Create(CreateCompanyCmd cmd) { var evtEntity = CompanyCreatedEvt.MakeEventEntity(cmd); var insertions = await eventRepository.Create(evtEntity); if (insertions == 0) { return(null); } return(await db.FirstAsync(c => c.CreatorEventId == evtEntity.Id)); }
// [RequiresAbsoluteRole(Role.Super, Role.Admin)] public async Task <IActionResult> CreateChildren(long companyId, [FromBody] CreateCompanyReq req) { req.ParentId = companyId; var userId = HttpContext.UserId().Value; var cmd = new CreateCompanyCmd(req, userId); var company = await companyRepo.Create(cmd); var cmd2 = new GivePermissionCmd( company.Id, userId, new CreatePermissionReq { RoleId = 601 }, userId ); var permission = await permissionRepo.Create(cmd2); return(Created($"/api/companies/${company.Id}", new CompanyResult(company))); }