public ActionResult CreateOrganisation([FromBody] OrganisationModelCreate organisationModel) { try { string userId = User.Identity.Name; int organisationId = _organisationService.CreateOrganisation(organisationModel, int.Parse(userId)); var organisationReadDto = _mapper.Map <OrganisationReadDto>(organisationModel); return(CreatedAtRoute("getOrganisationById", new { Id = organisationId }, organisationReadDto)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public int CreateOrganisation(OrganisationModelCreate organisationModel, int userId) { OrganisationModel om = new OrganisationModel(); DateTime now = DateTime.Now; om.Name = organisationModel.Name; om.CreatedAt = now; om.OrganisationType = organisationModel.OrganisationType; _context.Organisations.Add(om); _context.SaveChanges(); int id = om.Id; OrganisationListModel olm = new OrganisationListModel(); olm.OrganisationId = id; olm.UserId = userId; _context.OrganisationList.Add(olm); _context.SaveChanges(); return(id); }