public async Task UpdateOfficeAsync(UpdatedOffice updatedOffice)
        {
            var officeToUpdate = await Context.Organizations.Where(x => x.OrganizationId == updatedOffice.OfficeId)
                                 .Include(x => x.Contacts)
                                 .Include(x => x.OrganizationType)
                                 .FirstOrDefaultAsync();

            if (officeToUpdate != null)
            {
                officeToUpdate.Name         = updatedOffice.Name;
                officeToUpdate.OfficeSymbol = updatedOffice.OfficeSymbol;
                officeToUpdate.Description  = updatedOffice.Description;
                SetPointOfContacts(updatedOffice.PointsOfContactIds.ToList(), officeToUpdate);
                if (updatedOffice.ParentOfficeId.HasValue)
                {
                    var parentOffice = await Context.Organizations.FindAsync(updatedOffice.ParentOfficeId);

                    if (parentOffice != null)
                    {
                        officeToUpdate.ParentOrganizationId = parentOffice.OrganizationId;
                        officeToUpdate.ParentOrganization   = parentOffice;
                    }
                    else
                    {
                        throw new ModelNotFoundException("The office with the id [{0}] was not found.", updatedOffice.ParentOfficeId);
                    }
                }
                else
                {
                    officeToUpdate.ParentOrganizationId = null;
                    officeToUpdate.ParentOrganization   = null;
                }
            }
            else
            {
                throw new ModelNotFoundException("The office with the id [{0}] was not found.", updatedOffice.OfficeId);
            }
        }
Exemple #2
0
 public Task UpdateOfficeAsync(UpdatedOffice updatedOffice)
 {
     return(Task.FromResult <object>(null));
 }