public bool AddNewUser(string Login, string Password, HashSet <string> Roles)
 {
     try
     {
         if (Login == null || Password == null)
         {
             return(false);
         }
         foreach (User item in _userDao.GetAllUsers())
         {
             if (item.Login == Login)
             {
                 return(false);
             }
         }
         User user = new User {
             Login = Login, Password = Password
         };
         if (Roles == null)
         {
             user.Roles = new HashSet <string>();
         }
         else
         {
             user.Roles = Roles;
         }
         return(_userDao.AddNewUser(user));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
Пример #2
0
 public IEnumerable <Comment> GetAllCommentPhoto(int PhotoID)
 {
     try
     {
         LinkedList <Comment> AllComment = new LinkedList <Comment>();
         using (SqlConnection con = new SqlConnection(conStr))
         {
             SqlCommand cmd = con.CreateCommand();
             con.Open();
             cmd.CommandText = "dbo.GetAllCommentPhoto";
             cmd.CommandType = System.Data.CommandType.StoredProcedure;
             SqlDataReader sqlDataReader = cmd.ExecuteReader();
             while (sqlDataReader.Read())
             {
                 int    Id          = (int)sqlDataReader["Id"];
                 string Author      = (string)sqlDataReader["Author"];
                 int    IDPhoto     = (int)sqlDataReader["PhotoID"];
                 string TextComment = (string)sqlDataReader["TextComment"];
                 if (IDPhoto == PhotoID)
                 {
                     AllComment.AddLast(new Comment {
                         ID = Id, Author = Author, PhotoID = PhotoID, TextComment = TextComment
                     });
                 }
             }
         }
         return(AllComment);
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(null);
     }
 }
 public bool LikePhoto(int PhotoId, int LikedUserId)
 {
     try
     {
         Photo photo       = GetPhotoById(PhotoId);
         bool  UserInArray = false;
         foreach (int item in photo.LikeUsersList)
         {
             if (item == LikedUserId)
             {
                 UserInArray = true;
             }
         }
         if (!UserInArray)
         {
             return(_photoDao.LikePhoto(PhotoId, LikedUserId));
         }
         else
         {
             return(_photoDao.RemoveLikePhoto(PhotoId, LikedUserId));
         }
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
 public bool EditPhoto(int PhotoId, string NewTitle, string NewCounry)
 {
     try
     {
         if (PhotoId == 0 || (NewTitle == "" && NewCounry == ""))
         {
             return(false);
         }
         if (NewTitle == "")
         {
             NewTitle = _photoDao.GetPhotoById(PhotoId).Title;
         }
         if (NewCounry == "")
         {
             NewCounry = _photoDao.GetPhotoById(PhotoId).Country;
         }
         return(_photoDao.EditPhoto(PhotoId, NewTitle, NewCounry));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
 public User GetUserById(int UserID)
 {
     try
     {
         return(_userDao.GetUserById(UserID));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(null);
     }
 }
 public bool RemovePhoto(int PhotoId)
 {
     try
     {
         return(_photoDao.RemovePhoto(PhotoId));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
 public IEnumerable <Photo> GetAllPhoto()
 {
     try
     {
         HashSet <Photo> AllPhoto = new HashSet <Photo>();
         using (SqlConnection con = new SqlConnection(conStr))
         {
             SqlCommand cmd = con.CreateCommand();
             con.Open();
             cmd.CommandText = "dbo.GetAllPhoto";
             cmd.CommandType = System.Data.CommandType.StoredProcedure;
             SqlDataReader sqlDataReader   = cmd.ExecuteReader();
             User[]        usersAttachment = new User[] { };
             while (sqlDataReader.Read())
             {
                 int           Id            = (int)sqlDataReader["Id"];
                 string        Title         = (string)sqlDataReader["Title"];
                 string        Country       = (string)sqlDataReader["Country"];
                 int           AuthorId      = (int)sqlDataReader["AuthorId"];
                 byte[]        Image         = Convert.FromBase64String((string)sqlDataReader["Image"]);
                 int           LikeAuthorId  = 0;
                 HashSet <int> LikeUsersList = new HashSet <int> {
                 };
                 if (!System.DBNull.Value.Equals(sqlDataReader["User_Id"]))
                 {
                     LikeAuthorId = (int)sqlDataReader["User_Id"];
                     LikeUsersList.Add(LikeAuthorId);
                 }
                 Photo photo = new Photo {
                     Id = Id, Title = Title, Country = Country, AuthorId = AuthorId, LikeUsersList = LikeUsersList, Image = Image
                 };
                 Photo SerchPhoto = AllPhoto.FirstOrDefault(element => element.Id == photo.Id);
                 if (SerchPhoto != null && LikeAuthorId != 0)
                 {
                     SerchPhoto.LikeUsersList.Add(LikeAuthorId);
                 }
                 else
                 {
                     AllPhoto.Add(photo);
                 }
             }
         }
         return(AllPhoto);
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(null);
     }
 }
Пример #8
0
 public IEnumerable <User> GetAllUsers()
 {
     try
     {
         HashSet <User> AllUsers = new HashSet <User>();
         using (SqlConnection con = new SqlConnection(conStr))
         {
             SqlCommand cmd = con.CreateCommand();
             con.Open();
             cmd.CommandText = "dbo.GetAllUsers";
             cmd.CommandType = System.Data.CommandType.StoredProcedure;
             SqlDataReader sqlDataReader   = cmd.ExecuteReader();
             User[]        usersAttachment = new User[] { };
             while (sqlDataReader.Read())
             {
                 int              Id       = (int)sqlDataReader["Id"];
                 string           Login    = (string)sqlDataReader["Login"];
                 string           Password = (string)sqlDataReader["Password"];
                 string           Role     = "";
                 HashSet <string> Roles    = new HashSet <string> {
                 };
                 if (!System.DBNull.Value.Equals(sqlDataReader["RoleName"]))
                 {
                     Role = (string)sqlDataReader["RoleName"];
                     Roles.Add(Role);
                 }
                 User user = new User {
                     Id = Id, Login = Login, Password = Password, Roles = Roles
                 };
                 User SerchUser = AllUsers.FirstOrDefault(element => element.Login == user.Login);
                 if (SerchUser != null && Role != "")
                 {
                     SerchUser.Roles.Add(Role);
                 }
                 else
                 {
                     AllUsers.Add(user);
                 }
             }
         }
         return(AllUsers);
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(null);
     }
 }
 public bool RemoveUserRole(int UserID, string RoleName)
 {
     try
     {
         if (UserID == 0 || RoleName == null || RoleName == "")
         {
             return(false);
         }
         return(_userDao.RemoveUserRole(UserID, RoleName));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
 public Photo GetPhotoById(int PhotoId)
 {
     try
     {
         if (PhotoId == 0)
         {
             return(null);
         }
         return(_photoDao.GetPhotoById(PhotoId));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(null);
     }
 }
Пример #11
0
 public bool RemoveComment(int ID)
 {
     try
     {
         if (ID == 0)
         {
             return(false);
         }
         return(_commentDao.RemoveComment(ID));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
 public bool AddPhoto(string Title, string Country, byte[] Image, int AuthorId)
 {
     try
     {
         if (Title == null || Country == null || Image == null || AuthorId == 0)
         {
             return(false);
         }
         Photo photo = new Photo {
             AuthorId = AuthorId, Country = Country, Image = Image, Title = Title, LikeUsersList = new HashSet <int>()
         };
         return(_photoDao.AddPhoto(photo));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }
Пример #13
0
 public bool AddComment(int PhotoID, string Author, string TextComment)
 {
     try
     {
         if (PhotoID == 0 || Author == null || TextComment == null)
         {
             return(false);
         }
         Comment comment = new Comment {
             PhotoID = PhotoID, Author = Author, TextComment = TextComment
         };
         return(_commentDao.AddComment(comment));
     }
     catch (Exception ex)
     {
         MyLogger.AddLog(ex.Message, ex.StackTrace);
         Logger.Log.Error(ex.Message);
         return(false);
     }
 }