示例#1
0
        // GET: api/call
        public IHttpActionResult Post([FromBody] FavoriteDTO favorite)
        {
            if (favorite.AccountId == Guid.Empty || favorite.SpecwayId == Guid.Empty)
            {
                throw new ArgumentNullException();
            }

            var rfavDTO = _favoriteAppService.FindFavorite(favorite.SpecwayId, favorite.AccountId);

            if (rfavDTO == null || rfavDTO.Id == Guid.Empty)
            {
                var favoriteDTO = _favoriteAppService.AddNewFavorite(new Application.MainBoundedContext.DTO.FavoriteDTO()
                {
                    AccountId = favorite.AccountId,
                    SpecwayId = favorite.SpecwayId,
                    CreateOn  = DateTime.Now
                });
            }
            else
            {
                _favoriteAppService.RemoveFavoriteDTO(rfavDTO.Id);
            }

            return(Ok());
        }
示例#2
0
        public void GetIsFavorite_GetIsFavoriteIfPublicationHaveNotFavoriteByAuthorId_False()
        {
            // Arrange
            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

            var getFavorite = new GetFavorite(
                getablePublication.Object,
                getableUser.Object);

            getablePublication.Setup(gp => gp.GetById(_publicationsWithAuthor.FirstOrDefault().Id))
            .Returns(_publicationsWithAuthor.FirstOrDefault());

            var favoriteDTO = new FavoriteDTO()
            {
                PublicationId = _publicationsWithAuthor.FirstOrDefault().Id,
                UserId        = Guid.NewGuid(),
            };

            // Act
            var result = getFavorite.GetIsFavorite(favoriteDTO);

            // Assert
            Assert.False(result);
        }
示例#3
0
        public List <FavoriteDTO> GetAll()
        {
            List <FavoriteDTO> favorites = new List <FavoriteDTO>();

            try
            {
                using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                {
                    string sql = "SELECT * FROM Favorites";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        connection.Open();
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                FavoriteDTO favorite = new FavoriteDTO
                                {
                                    Id     = reader.GetInt32(0),
                                    UserId = reader.GetInt32(1),
                                    CarId  = reader.GetInt32(2)
                                };
                                favorites.Add(favorite);
                            }
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }

            return(favorites);
        }
示例#4
0
        public bool AddFavs(FavoriteDTO book)
        {
            CheckFavBook(book);
            int result = _BookManagement.InsertFavorite(book);

            return(result > 0);
        }
示例#5
0
        public FavoriteDTO Get(int favoriteId)
        {
            FavoriteDTO favorite = new FavoriteDTO();

            try
            {
                using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                {
                    string sql = "SELECT * FROM Favorites WHERE Id = (@Id)";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        connection.Open();
                        command.Parameters.AddWithValue("@Id", favoriteId);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            reader.Read();
                            favorite.UserId = reader.GetInt32(0);
                            favorite.CarId  = reader.GetInt32(1);
                        }
                        connection.Close();
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }

            return(favorite);
        }
示例#6
0
        public bool Create(FavoriteDTO favorite)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                {
                    string sql = "INSERT INTO Favorites (UserId, CarId) VALUES (@UserId, @CarId)";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        connection.Open();
                        command.Parameters.AddWithValue("@UserId", favorite.UserId);
                        command.Parameters.AddWithValue("@CarId", favorite.CarId);
                        if (command.ExecuteNonQuery() < 1)
                        {
                            connection.Close();
                            return(false);
                        }
                        connection.Close();
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }
示例#7
0
        private void btnAddFavs_Click(object sender, EventArgs e)
        {
            book = new BookDTO();
            foreach (DataGridViewRow row in dgvBooks.SelectedRows)
            {
                book.BookName       = row.Cells[0].Value.ToString();
                book.AuthorName     = row.Cells[1].Value.ToString();
                book.PublisherName  = row.Cells[2].Value.ToString();
                book.PublishingYear = (int)row.Cells[3].Value;
                book.PageCount      = (int)row.Cells[4].Value;
                book.Summary        = row.Cells[5].Value.ToString();
                book.Price          = (decimal)row.Cells[6].Value;
                book.IsAvailable    = (bool)row.Cells[7].Value;
            }
            selectedBooks.Add(book);
            int bookID = _bookController.GetBookIDByName(book.BookName, book.AuthorName);

            favBook        = new FavoriteDTO();
            favBook.BookID = bookID;
            favBook.UserID = user.UserID;
            try
            {
                bool result = _bookController.AddFavs(favBook);
                if (result)
                {
                    MessageBox.Show("Kayıt başarılı");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#8
0
        public void GetIsFavorite_GetIsFavoriteIfPublicationContainFavoriteByAuthorId_True()
        {
            // Arrange
            _publicationsWithAuthor.FirstOrDefault().Favorites.Add(_author);

            var getablePublication = new Mock <IGetablePublication>();
            var getableUser        = new Mock <IGetableUser>();

            var getFavorite = new GetFavorite(
                getablePublication.Object,
                getableUser.Object);

            getablePublication.Setup(gp => gp.GetById(_publicationsWithAuthor.FirstOrDefault().Id))
            .Returns(_publicationsWithAuthor.FirstOrDefault());

            var favoriteDTO = new FavoriteDTO()
            {
                PublicationId = _publicationsWithAuthor.FirstOrDefault().Id,
                UserId        = _author.Id,
            };

            // Act
            var result = getFavorite.GetIsFavorite(favoriteDTO);

            // Assert
            Assert.True(result);
        }
示例#9
0
        public int InsertFavorite(FavoriteDTO book)
        {
            string query = "INSERT INTO Favorite(UserID, BookID) VALUES(@userID,@bookID)";
            List <SqlParameter> parameters = GetParametersFavs(book);

            h.AddParametersToCommand(parameters);
            return(h.MyExecuteQuery(query));
        }
        public bool GetIsFavorite(FavoriteDTO favoriteDTO)
        {
            var publication = _getablePublication.GetById(favoriteDTO.PublicationId);
            var user        = publication.Favorites.FirstOrDefault(f => f.Id == favoriteDTO.UserId);
            var isFavorite  = user != null ? true : false;

            return(isFavorite);
        }
示例#11
0
        List <SqlParameter> GetParametersFavs(FavoriteDTO book)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@userID", book.UserID));
            parameters.Add(new SqlParameter("@bookID", book.BookID));
            return(parameters);
        }
示例#12
0
        public int UpdateFavorites(FavoriteDTO book)
        {
            string query = "UPDATE Favorite SET BookID = @bookID WHERE UserID = @userID";
            List <SqlParameter> parameters = GetParametersFavs(book);

            h.AddParametersToCommand(parameters);
            return(h.MyExecuteQuery(query));
        }
示例#13
0
        public FavoriteResultDTO LikeOrUnlike(FavoriteDTO favoriteDTO)
        {
            var author      = _getableUser.GetById(favoriteDTO.UserId);
            var publication = _getablePublication.GetById(favoriteDTO.PublicationId);
            var result      = InitFavorite(publication, author);

            result.IsLike = LikeOrUnlike(author, publication);
            return(result);
        }
示例#14
0
        public bool Create(Favorite favorite)
        {
            FavoriteDTO favoriteDTO = new FavoriteDTO()
            {
                Id     = 0,
                UserId = favorite.UserId,
                CarId  = favorite.CarId
            };

            return(FavoriteFactoryDAL.GetCollectionDAL().Create(favoriteDTO));
        }
示例#15
0
        public IHttpActionResult GetFavorite(int id)
        {
            FavoriteDTO favorite = _favoritesService.GetById(id);

            if (favorite == null)
            {
                return(NotFound());
            }

            return(Ok(favorite));
        }
示例#16
0
        public bool Update()
        {
            FavoriteDTO favoriteDTO = new FavoriteDTO
            {
                Id     = this.Id,
                UserId = this.UserId,
                CarId  = this.CarId
            };

            return(FavoriteFactoryDAL.GetDAL().Update(favoriteDTO));
        }
示例#17
0
 public ActionResult <bool> GetIsFavorite(FavoriteDTO favoriteDTO)
 {
     try
     {
         return(Ok(_getableFavorite.GetIsFavorite(favoriteDTO)));
     }
     catch (ObjectNotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
 }
 public ActionResult <FavoriteResultDTO> LikeOrUnlike(FavoriteDTO favoriteDTO)
 {
     try
     {
         return(Ok(_likeableFavorite.LikeOrUnlike(favoriteDTO)));
     }
     catch (ObjectNotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
 }
示例#19
0
        void CheckFavBook(FavoriteDTO book)
        {
            List <FavoriteDTO> favs = _BookManagement.GetAllFavDTOs();

            foreach (FavoriteDTO item in favs)
            {
                if (item.BookID == book.BookID && item.UserID == book.UserID)
                {
                    throw new AlreadyAddedException();
                }
            }
        }
示例#20
0
        public void ChooseFavorite(FavoriteDTO favoriteDto)
        {
            Favorite favorite = Database.Favorites.Get(favoriteDto.userid);

            // валидация
            if (favorite == null)
            {
                throw new ValidationException("Not Found", "");
            }
            Favorite nfavorite = new Favorite
            {
            };

            Database.Favorites.Create(nfavorite);
            Database.Save();
        }
示例#21
0
        public List <FavoriteDTO> GetAll()
        {
            using (var db = new ModelContext())
            {
                List <Favorite>    favorites = db.Favorites.ToList();
                List <FavoriteDTO> dtos      = new List <FavoriteDTO>();

                foreach (var favorite in favorites)
                {
                    FavoriteDTO dto = new FavoriteDTO();
                    dto.Id         = favorite.Id;
                    dto.CategoryId = favorite.CategoryId;
                    dtos.Add(dto);
                }
                return(dtos);
            }
        }
示例#22
0
        public IActionResult AddFavoriteMovie(FavoriteDTO favoriteDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("failed favorite!!"));
            }
            var favorite = _mapper.Map <FavoriteDTO, Favorite>(favoriteDto);

            if (_userService.AddFavoriteMovie(favorite) != null)
            {
                return(Ok("success favorite!!"));
            }
            else
            {
                return(BadRequest("failed favorite!!"));
            }
        }
        /// <summary>
        /// news a account
        /// </summary>
        /// <param name="favoriteDTO"></param>
        /// <returns></returns>
        public FavoriteDTO AddNewFavorite(FavoriteDTO favoriteDTO)
        {
            //check preconditions
            if (favoriteDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddFavoriteWithEmptyInformation);
            }

            //Create the entity and the required associated data
            var favorite = FavoriteFactory.CreateFavorite(favoriteDTO.AccountId, favoriteDTO.SpecwayId);

            //save entity
            SaveFavorite(favorite);

            //return the data with id and assigned default values
            return(favorite.ProjectedAs <FavoriteDTO>());
        }
示例#24
0
        public List <FavoriteDTO> GetAllFavDTOs()
        {
            List <FavoriteDTO> books       = new List <FavoriteDTO>();
            FavoriteDTO        currentBook = null;
            string             query       = "SELECT UserID,BookID FROM Favorite";

            SqlDataReader reader = h.MyExecuteReader(query);

            while (reader.Read())
            {
                currentBook        = new FavoriteDTO();
                currentBook.BookID = (int)reader["BookID"];
                currentBook.UserID = (int)reader["UserID"];
                books.Add(currentBook);
            }
            reader.Close();
            return(books);
        }
示例#25
0
 public bool Update(FavoriteDTO favorite)
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(sqlConnectionString))
         {
             string sql = "UPDATE Favorites SET CarId = (@CarId) WHERE Id = (@Id)";
             using (SqlCommand command = new SqlCommand(sql, connection))
             {
                 connection.Open();
                 command.Parameters.AddWithValue("@CarId", favorite.CarId);
                 command.Parameters.AddWithValue("@Id", favorite.Id);
                 command.ExecuteNonQuery();
                 connection.Close();
             }
         }
     }
     catch (SqlException e)
     {
         Console.WriteLine(e);
         return(false);
     }
     return(true);
 }
示例#26
0
        public bool UpdateFavs(FavoriteDTO book)
        {
            int result = _BookManagement.UpdateFavorites(book);

            return(result > 0);
        }