示例#1
0
        /// <inheritdoc/>
        public HistoryModel InsertNewHistoryElement(int userId, int targetId, string status)
        {
            var historyModel = new HistoryModel()
            {
                UserId   = userId,
                TargetId = targetId,
                Status   = status
            };

            using (var context = _databaseContextGeneration.BuildDatabaseContext())
            {
                context.History.Add(historyModel);
                context.SaveChanges();
            }

            return(historyModel);
        }
        /// <inheritdoc/>
        public FaceFeaturesModel InsertNewFeaturesModel(int personId, int age, string gender)
        {
            var element = new FaceFeaturesModel()
            {
                PersonId = personId,
                Age      = age,
                Gender   = gender
            };

            using (var context = _databaseContextGeneration.BuildDatabaseContext())
            {
                context.FaceFeatures.Add(element);
                context.SaveChanges();
            }

            return(element);
        }
        /// <inheritdoc/>
        public TargetElement InsertNewTargetElement(int id, int hunterPersonId, int preyPersonId, bool isHunted = false)
        {
            //Creates an element to insert in DB
            var targetElement = new TargetElement()
            {
                Id             = id,
                HunterPersonId = hunterPersonId,
                PreyPersonId   = preyPersonId,
                IsHunted       = isHunted
            };

            //Inserts element into TargetElements
            using (var context = _databaseContextGeneration.BuildDatabaseContext())
            {
                context.TargetElements.Add(targetElement);
                context.SaveChanges();
            }

            return(targetElement);
        }
示例#4
0
        /// <inheritdoc/>
        public DatabaseImageElement InsertNewImageElement(int id, string imageName, string imageContentUri, string personFirstName, string personLastName, string descriptiveSentence, int score)
        {
            if (!Uri.IsWellFormedUriString(imageContentUri, UriKind.Absolute))
            {
                throw new ManagerException(StorageErrorMessages.InvalidImageUriError);
            }

            if (!imageName.IsFileNameValid())
            {
                throw new ManagerException(StorageErrorMessages.InvalidFileNameError);
            }

            //Creates an element to insert into DB
            var imageElement = new DatabaseImageElement()
            {
                Id                  = id,
                ImageName           = imageName,
                ImageContentUri     = imageContentUri,
                PersonFirstName     = personFirstName,
                PersonLastName      = personLastName,
                DescriptiveSentence = descriptiveSentence,
                Score               = score
            };

            //Inserts element into DatabaseImageElements
            using (var context = _databaseContextGeneration.BuildDatabaseContext())
            {
                if (context.DatabaseImageElements.Any(s => s.ImageContentUri == imageElement.ImageContentUri))
                {
                    return(null);
                }

                context.DatabaseImageElements.Add(imageElement);
                context.SaveChanges();
            }

            return(imageElement);
        }