public void RemoveOrganization(OrganizationEntity organizationEntity)
        {
            var result = _directoryContext.OrganizationEntities.SingleOrDefault(p => p.OrganizationName == organizationEntity.OrganizationName);

            _directoryContext.Entry(result).State = EntityState.Deleted;
            _directoryContext.SaveChanges();
        }
Exemple #2
0
        public void UploadFiles(Files filesList, long id = 0)
        {
            var directory = GetDirectory(id);

            if (directory == null)
            {
                throw new Exception("Directory is Invalid");
            }

            var filesOnServer = directory.File.ToDictionary(r => r.Name);

            try
            {
                foreach (var file in filesList)
                {
                    if (!filesOnServer.ContainsKey(file.Name))
                    {
                        directory.File.Add(file);
                        db.Entry(file).State = System.Data.EntityState.Added;
                    }
                }
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                throw;
            }
        }
Exemple #3
0
        public async Task <ActionResult <Person> > GetPerson(Guid id)
        {
            var person = await _context.People.FindAsync(id);

            if (person == null)
            {
                return(NotFound());
            }

            await _context.Entry(person).Collection(p => p.FamilyRoles).LoadAsync();

            return(person);
        }
        public async Task <ActionResult <Family> > GetFamily(Guid id)
        {
            var family = await _context.Families.FindAsync(id);

            if (family == null)
            {
                return(NotFound());
            }

            await _context.Entry(family).Collection(f => f.FamilyMembers).LoadAsync();

            return(family);
        }
Exemple #5
0
        public void RemoveCommunicationType(CommunicationTypeEntity communicationMethodEntity)
        {
            var result = _directoryContext.CommunicationTypeEntities.SingleOrDefault(p => p.Type == communicationMethodEntity.Type);

            _directoryContext.Entry(result).State = EntityState.Deleted;
            _directoryContext.SaveChanges();
        }
        public void AddCommunicationMethod(ContactEntity contactEntity, CommunicationMethodEntity communicationMethodEntity)
        {
            var result = _directoryContext.CommunicationMethodEntities
                         .SingleOrDefault(p => p.Address == communicationMethodEntity.Address && p.TypeId == communicationMethodEntity.TypeId && p.ContactId == contactEntity.ContactId);

            if (result == null)
            {
                communicationMethodEntity.ContactId = contactEntity.ContactId;
                _directoryContext.CommunicationMethodEntities.Add(communicationMethodEntity);
                _directoryContext.SaveChanges();
                _directoryContext.Entry(communicationMethodEntity).Reload();
            }
            else
            {
                throw new System.Exception("An entry with this address is already exists");
            }
        }
        public async Task <IActionResult> UpdateBrother(int brotherId, [FromBody] Brother newBrotherModel)
        {
            Brother brother = await _dbContext.Brother.FindBrotherByIdAsync(brotherId);

            if (brother == null)
            {
                return(NotFound());
            }

            if (newBrotherModel.Id != brotherId)
            {
                return(BadRequest());
            }

            string?subject = _principal.GetSubjectId();

            if (string.IsNullOrEmpty(subject))
            {
                // Well, this shouldn't happen, but just to be sure.
                return(Unauthorized());
            }

            IEnumerable <string> scopes = _principal.GetScopes();

            // TODO: I think there's a better way to do this (and the bit above), having the authorization filter do it instead, though this requires several things:
            // (1) the route to be consistent; (2) the parameter to either be obtained from the route in the authorization handler or obtainable
            // there via an injected service; and (3) access to the claims principal.
            // However, doing this would prevent this boilerplate every time. It should also be its own authorization policy so that it doesn't apply everywhere.
            if (!subject.Equals(brother.Id.ToString()))
            {
                // If the user isn't the brother they're trying to update and doesn't have the administrator scope, reject the request.
                if (!scopes.Contains(Constants.Scopes.Administrator))
                {
                    _logger.LogInformation("Rejecting request from user with identifier {subject} attempting to modify {brotherFirst} {brotherLast}: the user is not an administrator.",
                                           subject, brother.FirstName, brother.LastName);
                    return(Unauthorized());
                }

                // User is an administrator
                _logger.LogTrace("Administrator (subject {subjectId}) updating {first} {last}.", subject,
                                 brother.FirstName, brother.LastName);
            }

            try {
                _dbContext.Entry(brother).CurrentValues.SetValues(newBrotherModel);

                await _dbContext.SaveChangesAsync();
            } catch (DbUpdateConcurrencyException) {
                return(Conflict());
            }

            return(Ok());
        }
Exemple #8
0
 public void UpdateDirectory(Directory directory)
 {
     db.Entry(directory).State = System.Data.EntityState.Modified;
     CommitChanges();
 }