Esempio n. 1
0
        public bool AddLike(Like like)
        {
            using (var connection = new SqlConnection(this.connectionString))
            {
                var storeProcedure = "Like_AddLike";

                var command = new SqlCommand(storeProcedure, connection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                command.Parameters.AddWithValue("@photoId", like.PhotoId);
                command.Parameters.AddWithValue("@userId", like.UserId);
                command.Parameters.AddWithValue("@date", like.Date);

                connection.Open();
                var reader = command.ExecuteReader();
                if (reader.Read())
                {
                    like.Id = (int)(decimal)reader["newId"];
                }
                else
                {
                    return false;
                }

                return true;
            }
        }
Esempio n. 2
0
        private bool IsValidLike(Like like)
        {
            if (like.PhotoId <= 0 || like.UserId <= 0)
            {
                throw new ArgumentException($"{nameof(like.PhotoId)} or {nameof(like.UserId)} mustn't be negative");
            }

            if (like.Date > DateTime.Now)
            {
                throw new ArgumentException("Date mustn't be in the future");
            }

            return true;
        }
Esempio n. 3
0
        public bool AddLike(Like like)
        {
            var result = false;

            try
            {
                this.IsValidLike(like);
                result = Stores.LikeStore.AddLike(like);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }