// Create and add new organisation in the database. public async Task <IEnumerable <OrganisationDto> > AddOrganisation([FromBody] NewOrganisationFromClient organisation) { _orgsDataBase.Organisations.Add(new Models.Organisation() { FullName = organisation.Name, ShortName = organisation.ShortName, Adress = organisation.Adress, Telephone = organisation.Telephone }); await _orgsDataBase.SaveChangesAsync(); return((await _orgsDataBase.Organisations.ToListAsync()) .Select(item => _mapper.Map <OrganisationDto>(item))); }
// Update choosen organisation with changes. public async Task <IEnumerable <User> > UpdateOrganisation([FromBody] NewOrganisationFromClient organisation, int id) { var updatingOrganisation = await _orgsDataBase.Organisations .Where(selectedOrganisation => selectedOrganisation.Id == id) .FirstOrDefaultAsync(); updatingOrganisation.FullName = organisation.Name; updatingOrganisation.ShortName = organisation.ShortName; updatingOrganisation.Adress = organisation.Adress; updatingOrganisation.Telephone = organisation.Telephone; _orgsDataBase.Organisations.Update(updatingOrganisation); await _orgsDataBase.SaveChangesAsync(); return(await _orgsDataBase.Users .Include(user => user.Attachments) .ThenInclude(attachment => attachment.Organisation) .ToListAsync()); }