Esempio n. 1
0
        public static int Create(Group group)
        {
            try
            {
                using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
                {
                    if (context.Groups.FirstOrDefault(g => g.Name == group.Name) == null)
                    {
                        context.Groups.Add(group);
                        context.SaveChanges();

                        var UserSearch  = context.Users.Include("Group").First(u => u.Id == group.UserOwnerId);
                        var GroupSearch = context.Groups.Include("Users").First(g => g.Id == group.Id);
                        UserSearch.Group.Add(GroupSearch);
                        return(context.SaveChanges());
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Esempio n. 2
0
        public static User Create(User user)
        {
            try
            {
                using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
                {
                    // check user already exist
                    user.Group = null;
                    user.Likes = null;
                    user.Posts = null;
                    if (context.Users.Where(s => s.Email == user.Email).FirstOrDefault() == null)
                    {
                        // create user
                        context.Users.Add(user);

                        // assign group to user
                        string   email      = user.Email;
                        string[] split      = email.Split('@');
                        string   nomDomaine = split[1].ToString();
                        split = nomDomaine.Split('.');
                        string nomGroupe = split[0].ToString();

                        // check group already exist
                        Group existGroup = context.Groups.Where(s => s.Name == nomGroupe).FirstOrDefault();

                        if (existGroup == null)
                        {
                            Group groupForUser = new Group();
                            groupForUser.Name        = nomGroupe;
                            groupForUser.UserOwnerId = user.Id;
                            context.Groups.Add(groupForUser);
                            context.SaveChanges();
                            User_Repo.AddUserToGroup(user.Id, groupForUser.Id);
                        }
                        else
                        {
                            context.SaveChanges();
                            User_Repo.AddUserToGroup(user.Id, existGroup.Id);
                        }

                        context.SaveChanges();
                        return(user);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        public static int Delete(int id)
        {
            try
            {
                using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
                {
                    Post Delete = context.Posts.Include("Likes").First(s => s.Id == id);

                    //Delete picture
                    if (Delete.Picture != null)
                    {
                        try
                        {
                            System.IO.File.Delete(Delete.Picture);
                        }
                        catch (System.IO.IOException e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    context.Posts.Remove(Delete);
                    return(context.SaveChanges());
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Esempio n. 4
0
 public static int Create(Like like)
 {
     try
     {
         using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
         {
             context.Likes.Add(like);
             return(context.SaveChanges());
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Esempio n. 5
0
 public static int Create(Comment comment)
 {
     try
     {
         using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
         {
             context.Comments.Add(comment);
             return(context.SaveChanges());
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Esempio n. 6
0
 public static int Delete(int id)
 {
     try
     {
         using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
         {
             Like delete = context.Likes.Find(id);
             context.Likes.Remove(delete);
             return(context.SaveChanges());
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Esempio n. 7
0
 public static int AddPictureToAPost(Post post, String pathPicture)
 {
     try
     {
         using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
         {
             Post postEdit = context.Posts.Find(post.Id);
             postEdit.Picture = pathPicture;
             return(context.SaveChanges());
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Esempio n. 8
0
 public static int RemoveFollow(int idUser, int IdUserDestinataire)
 {
     try
     {
         using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
         {
             User userDestinataire = context.Users.Include("Users").Where(s => s.Id == IdUserDestinataire).First();
             User user             = context.Users.Include("Follow").Where(s => s.Id == idUser).First();
             user.Follow.Remove(userDestinataire);
             return(context.SaveChanges());
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Esempio n. 9
0
        public static int RemoveUserFromGroup(int idUser, int idGroup)
        {
            try
            {
                using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
                {
                    User  userSearch  = context.Users.Include("Group").First(s => s.Id == idUser);
                    Group groupSearch = context.Groups.Include("Users").First(s => s.Id == idGroup);

                    userSearch.Group.Remove(groupSearch);

                    return(context.SaveChanges());
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Esempio n. 10
0
        public static Post Create(Post post, int idUser, int idGroup)
        {
            try
            {
                using (ZoombuM1ServiceContext context = new ZoombuM1ServiceContext())
                {
                    User  userSearch  = context.Users.Include("Group").Single(s => s.Id == idUser);
                    Group groupSearch = context.Groups.Include("User").Single(s => s.Id == idGroup);
                    post.Group = groupSearch;
                    post.User  = userSearch;

                    context.Posts.Add(post);
                    context.SaveChanges();
                    return(post);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }