Beispiel #1
0
 /// <summary>
 /// Adds user to DB (Registering a user)
 /// </summary>
 /// <param name="user"></param>
 public void Register(User user)
 {
     using (PsychoCareContext db = _contextBuilder.GetContext())
     {
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
Beispiel #2
0
 /// <summary>
 /// Adds to DB emotional state
 /// </summary>
 /// <param name="emotionalState"></param>
 public void AddEmotionalState(EmotionalState emotionalState)
 {
     using (PsychoCareContext db = _contextBuilder.GetContext())
     {
         db.EmotionalStates.Add(emotionalState);
         db.SaveChanges();
     }
 }
Beispiel #3
0
 /// <summary>
 /// Gets user by email adress otherwise null
 /// </summary>
 /// <param name="email"></param>
 /// <returns></returns>
 public User FindUserByEmail(string email)
 {
     using (PsychoCareContext db = _contextBuilder.GetContext())
     {
         User user = db.Users.AsNoTracking()
                     .FirstOrDefault(x => x.Email == email);
         return(user);
     }
 }
        /// <summary>
        /// Deletes environment group
        /// </summary>
        /// <param name="environmentGroupId"></param>
        public void DeleteEnvironmentGroup(int environmentGroupId)
        {
            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                EnvironmentGroup environmentGroup = db.EnvironmentGroups.Find(environmentGroupId);

                db.EnvironmentGroups.Remove(environmentGroup);
                db.SaveChanges();
            }
        }
        /// <summary>
        /// Adds environment group
        /// </summary>
        /// <param name="environmentGroup"></param>
        /// <returns></returns>
        public int AddEnvironmentGroup(EnvironmentGroup environmentGroup)
        {
            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                db.EnvironmentGroups.Add(environmentGroup);
                db.SaveChanges();
            }

            return(environmentGroup.Id);
        }
        /// <summary>
        /// Gets environment group by user id and environment group name
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public EnvironmentGroup GetEnvironmentGroupByUserAndName(int userId, string name)
        {
            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                EnvironmentGroup environmentGroup
                    = db.EnvironmentGroups.AsNoTracking()
                      .FirstOrDefault(x => x.UserId == userId && x.Name.ToLower() == name);

                return(environmentGroup);
            }
        }
        /// <summary>
        /// Gets environment group by id
        /// </summary>
        /// <param name="environmentGroupId"></param>
        /// <returns></returns>
        public EnvironmentGroup GetEnvironmentGroupById(int environmentGroupId)
        {
            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                EnvironmentGroup environmentGroup
                    = db.EnvironmentGroups.AsNoTracking()
                      .FirstOrDefault(x => x.Id == environmentGroupId);

                return(environmentGroup);
            }
        }
        /// <summary>
        /// Edits environment group
        ///
        /// Speccialy edits only name
        /// </summary>
        /// <param name="environmentGroup"></param>
        public void EditEnvironmentGroupName(EnvironmentGroup environmentGroup)
        {
            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                EnvironmentGroup environmentGroupDb = db.EnvironmentGroups
                                                      .FirstOrDefault(x => x.Id == environmentGroup.Id);

                environmentGroupDb.Name = environmentGroup.Name;
                db.SaveChanges();
            }
        }
        private static PsychoCareContext GetInMemoryContext()
        {
            var options = new DbContextOptionsBuilder <PsychoCareContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .Options;

            var context = new PsychoCareContext(options);

            return(context);
        }
        /// <summary>
        /// Gets all user environment groups
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <EnvironmentGroup> GetUserEnvironmentGroups(int userId)
        {
            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                List <EnvironmentGroup> environmentGroups
                    = db.EnvironmentGroups.AsNoTracking()
                      .Where(x => x.UserId == userId)
                      .ToList();

                return(environmentGroups);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Downloads all user emotional states
        /// and includes them environment groups
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <EmotionalState> GetEmotionalStates(int userId)
        {
            List <EmotionalState> emotionalStates = null;

            using (PsychoCareContext db = _contextBuilder.GetContext())
            {
                emotionalStates = db.EmotionalStates.AsNoTracking()
                                  .Where(x => x.UserId == userId)
                                  .Include(x => x.EnvironmentGroup)
                                  .ToList();
            }

            return(emotionalStates);
        }