Exemple #1
0
 public bool AddUser(User user)
 {
     using (var context = dbContext.CreateDbContext(DBOptions.Write))
     {
         context.Add(user);
         return(context.SaveChanges() > 0);
     }
 }
Exemple #2
0
        public LogInDetailModelDTO AddLog(LogInDetailModelDTO log)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newLog = mapper.MapDetailToEntity(log);

                newLog.Id            = Guid.NewGuid();
                newLog.SignInLogTime = DateTime.Now;

                connection.SignInLogs.Add(newLog);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newLog));
            }
        }
Exemple #3
0
        public FileDetailModelDTO AddFile(FileDetailModelDTO file)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newFile = mapper.MapDetailToEntity(file);

                connection.Files.Add(newFile);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newFile));
            }
        }
Exemple #4
0
        public UserDetailModelDTO AddUser(UserDetailModelDTO user)
        {
            using (var Connection = chatterDbContextFactory.CreateDbContext())
            {
                var newUser = mapper.MapDetailToEntity(user);
                newUser.Id = Guid.NewGuid();

                var pass = Crypto.Encrypt(user.Password);

                newUser.Password = pass.Hash;
                newUser.Salt     = pass.Salt;

                Connection.Users.Add(newUser);

                Connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newUser));
            }
        }
Exemple #5
0
        public PostDetailModelDTO AddPost(PostDetailModelDTO post)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newPost = mapper.MapDetailToEntity(post);

                newPost.Id       = Guid.NewGuid();
                newPost.DateTime = DateTime.Now;

                connection.Users.Attach(newPost.User);
                connection.Posts.Add(newPost);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newPost));
            }
        }
Exemple #6
0
        public GroupDetailModelDTO AddGroup(GroupDetailModelDTO group)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newGroup = mapper.MapDetailToEntity(group);

                foreach (var admin in group.Admins)
                {
                    var adminDet = connection.Users.Single(x => x.Id == admin.Id);
                    connection.Users.Attach(adminDet);

                    connection.Admin_Group.Add(new Admin_Group()
                    {
                        Id         = Guid.NewGuid(),
                        Admin      = adminDet,
                        AdminRefId = adminDet.Id,
                        Group      = newGroup,
                        GroupRefId = newGroup.Id
                    });
                }

                foreach (var user in group.Users)
                {
                    var userDet = connection.Users.Single(x => x.Id == user.Id);
                    connection.Users.Attach(userDet);

                    connection.User_Group.Add(new User_Group()
                    {
                        Id         = Guid.NewGuid(),
                        User       = userDet,
                        UserRefId  = userDet.Id,
                        Group      = newGroup,
                        GroupRefId = newGroup.Id
                    });
                }

                connection.Groups.Add(newGroup);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newGroup));
            }
        }
Exemple #7
0
        public CommentDetailModelDTO AddComment(CommentDetailModelDTO comment)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newComment = mapper.MapDetailToEntity(comment);

                connection.Users.Attach(mapper.MapDetailToEntity(comment.User));

                var post = connection.Posts.Single(x => x.Id == comment.Post.Id);
                newComment.Post = post;
                connection.Posts.Attach(post);

                connection.Comments.Add(newComment);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newComment));
            }
        }
Exemple #8
0
        public OrganizationDetailModelDTO AddOrganization(OrganizationDetailModelDTO organization)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newOrganization = mapper.MapDetailToEntity(organization);

                foreach (var admin in organization.Admins)
                {
                    var adminDet = connection.Users.Single(x => x.Id == admin.Id);
                    connection.Users.Attach(adminDet);

                    connection.Admin_Organization.Add(new Admin_Organization()
                    {
                        Id                = Guid.NewGuid(),
                        Admin             = adminDet,
                        AdminRefId        = adminDet.Id,
                        Organization      = newOrganization,
                        OrganizationRefId = newOrganization.Id
                    });
                }

                foreach (var user in organization.Users)
                {
                    var userDet = connection.Users.Single(x => x.Id == user.Id);
                    connection.Users.Attach(userDet);

                    connection.User_Organization.Add(new User_Organization()
                    {
                        Id                = Guid.NewGuid(),
                        User              = userDet,
                        UserRefId         = userDet.Id,
                        Organization      = newOrganization,
                        OrganizationRefId = newOrganization.Id
                    });
                }

                connection.Organizations.Add(newOrganization);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newOrganization));
            }
        }