Beispiel #1
0
        public static UserDto Unsubscribe(UnsuscribeRequest request)
        {
            using (familydbEntities1 db = new familydbEntities1())
            {
                var usr = db.User.Include(a => a.Groups).SingleOrDefault(a => a.Id == request.UserId);

                if (usr != null)
                {
                    foreach (var grp in usr.Groups
                             .Where(u => u.User.Contains(usr)).ToList())
                    {
                        usr.Groups.Remove(grp);
                        db.SaveChanges();
                    }

                    db.User.Remove(usr);
                    db.SaveChanges();
                }

                if (usr == null)
                {
                    return(null);
                }
                return(Convertion.UserConvertion.ConvertToDto(usr));
            }
        }
        public static UserDto AddUserToGroup(AddUeserToGroupRequest request)
        {
            using (familydbEntities1 db = new familydbEntities1())
            {
                var group = db.Groups.Include(a => a.User).SingleOrDefault(a => a.Id == request.GroupId);
                var user  = db.User.FirstOrDefault(u => u.Mail == request.Mail);
                if (user == null)
                {
                    user = db.User.Add(Convertion.GroupsConvertion.ConvertAddUeserToGroupToUser(request));
                    db.SaveChanges();
                    if (user == null)
                    {
                        return(null);
                    }
                }
                if (group.User.FirstOrDefault(u1 => u1.Mail == request.Mail) == null)
                {
                    group.User.Add(user);
                    db.SaveChanges();
                    EmailSender.send(request.Mail, group.Name, user.Password, user.UserName, request.UserSender);
                }


                return(Convertion.UserConvertion.ConvertToDto(user));
            }
        }
        public static GroupsDto DeleteUserFromGroup(DeleteUserFromGroupRequest request)
        {
            using (familydbEntities1 db = new familydbEntities1())
            {
                var group = db.Groups.Include(a => a.User).SingleOrDefault(a => a.Id == request.GroupId);

                if (group != null)
                {
                    var user = group.User.FirstOrDefault(u => u.Id == request.UserId);
                    if (user != null)
                    {
                        group.User.Remove(user);
                        if (group.User.Count == 0)
                        {
                            db.Groups.Remove(group);
                            group = null;
                        }

                        db.SaveChanges();
                    }
                    if (group != null)
                    {
                        return(Convertion.GroupsConvertion.ConvertToDto(group));
                    }
                }
                return(null);
            }
        }
 public static GroupsDto AddGroup(AddGroupRequest request)
 {
     using (familydbEntities1 db = new familydbEntities1())
     {
         Groups group = db.Groups.Add(Convertion.GroupsConvertion.ConvertAddGroupRequestToUser(request));
         db.SaveChanges();
         if (group == null)
         {
             return(null);
         }
         User user = db.User.FirstOrDefault(x => x.Id == request.UserId);
         group.User.Add(user);
         db.SaveChanges();
         return(Convertion.GroupsConvertion.ConvertToDto(group));
     }
 }
Beispiel #5
0
 public static ChatMessagesDto AddChatMessage(AddChatMessageRequest request)
 {
     using (familydbEntities1 db = new familydbEntities1())
     {
         ChatMessages msg = db.ChatMessages.Add(Convertion.ChatMessagesConvertor.ConvertAddChatMessageRequestToChatMessages(request));
         db.SaveChanges();
         if (msg == null)
         {
             return(null);
         }
         return(Convertion.ChatMessagesConvertor.ConvertToDto(msg));
     }
 }
Beispiel #6
0
 public static UserDto UpdateUser(UpdateUserRequest request)
 {
     using (familydbEntities1 db = new familydbEntities1())
     {
         User user = new User();
         User find = db.User.ToList().FirstOrDefault(u => u.Id == request.Id);
         if (find != null)
         {
             user = Convertion.UserConvertion.ConvertUpdateUserRequestToUser(request);
             db.User.AddOrUpdate(user);
             db.SaveChanges();
         }
         else
         {
             return(null);
         }
         return(Convertion.UserConvertion.ConvertToDto(user));
     }
 }
Beispiel #7
0
 public static UserDto SignUp(UserRequest request)
 {
     using (familydbEntities1 db = new familydbEntities1())
     {
         User user = new User();
         User find = db.User.ToList().FirstOrDefault(u => u.Password == request.Password && u.UserName == request.UserName);
         if (find == null)
         {
             user = db.User.Add(Convertion.UserConvertion.ConvertUserRequestToUser(request));
             db.SaveChanges();
             if (user == null)
             {
                 return(null);
             }
         }
         else
         {
             return(null);
         }
         return(Convertion.UserConvertion.ConvertToDto(user));
     }
 }
        public static GroupsDto DeleteGroup(DeleteGroupRequest request)
        {
            using (familydbEntities1 db = new familydbEntities1())
            {
                var group = db.Groups.Include(a => a.User).SingleOrDefault(a => a.Id == request.GroupId);

                if (group != null)
                {
                    foreach (var user in group.User
                             .Where(u => u.Groups.Contains(group)).ToList())
                    {
                        group.User.Remove(user);
                    }
                    db.Groups.Remove(group);
                    db.SaveChanges();
                }

                if (group == null)
                {
                    return(null);
                }
                return(Convertion.GroupsConvertion.ConvertToDto(group));
            }
        }