Esempio n. 1
0
        public IEnumerable <ServiceReview> GetAllReviewsByProductId(int productId)
        {
            List <ServiceReview> reviews = new List <ServiceReview>();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand cmdGetAllReviews = connection.CreateCommand())
                {
                    cmdGetAllReviews.CommandText = "SELECT reviewId, comment, rating FROM Review WHERE productId = @productId";
                    cmdGetAllReviews.Parameters.AddWithValue("productId", productId);
                    SqlDataReader reviewReader = cmdGetAllReviews.ExecuteReader();

                    while (reviewReader.Read())
                    {
                        ServiceReview review = new ServiceReview();
                        review.ReviewId = reviewReader.GetInt32(reviewReader.GetOrdinal("reviewId"));
                        review.Comment  = reviewReader.GetString(reviewReader.GetOrdinal("comment"));
                        review.Rating   = reviewReader.GetInt32(reviewReader.GetOrdinal("rating"));

                        reviews.Add(review);
                    }
                }
            }
            return(reviews);
        }
        public ServiceReview UploadFile(HttpPostedFileBase uploadFile, int?currentDirectory, User currenUser, IFileUploadSystemData data)
        {
            var res = new ServiceReview();
            var currentDirectoryId = currentDirectory ?? -1;

            res.RedirectId = currentDirectory;
            var errorFound = false;

            if (uploadFile == null ||
                uploadFile.ContentLength == 0 ||
                uploadFile.ContentLength > GlobalConstants.MaxUploadFileSize ||
                uploadFile.FileName.Trim().Length < 1)
            {
                res.Message    = "Bad file name/size!";
                res.ErrorFound = true;
                return(res);
            }

            var fileName      = Path.GetFileName(uploadFile.FileName);
            var fileExtension = Path.GetExtension(uploadFile.FileName);

            // Check if the same filename allready exists in current directory
            errorFound = CommonFunc.SameFileExistInSameDir(fileName, currentDirectoryId, currenUser);
            if (errorFound)
            {
                res.ErrorFound = true;
                res.Message    = "A file with that name already exists in the current directory!";
                return(res);
            }

            var newFile = new BinaryFile
            {
                Name       = fileName,
                Type       = fileExtension,
                Size       = uploadFile.ContentLength,
                Owner      = currenUser,
                OwnerId    = currenUser.Id,
                LocationId = currentDirectoryId
            };

            if (currentDirectory != -1)
            {
                ((DirectoryEntity)currenUser.Files.Where(f => f.Id == currentDirectory).FirstOrDefault()).FilesContained.Add(newFile);
            }
            else
            {
                currenUser.Files.Add(newFile);
            }

            data.SaveChanges();
            int id = newFile.Id;

            FileManipulator.UploadFile(uploadFile, id, fileExtension);

            res.Message = string.Format("File ({0}) uploaded successfully!", fileName);
            return(res);
        }
Esempio n. 3
0
        public static ReviewModel GetReviewModel(ServiceReview review)
        {
            UserShortModel user = manager.userService.GetUserProfile(review.UserID)?.ToUserShortModel() ??
                                  new ServiceUserProfile()
            {
                ID = review.UserID
            }.ToUserShortModel();

            return(review.ToReviewModel(user, Book.GetBookShortModel(review.BookID, review.UserID)));
        }
Esempio n. 4
0
 public static DalReview ToDalReview(this ServiceReview review)
 {
     return(new DalReview
     {
         ID = review.ID,
         BookID = review.BookID,
         UserID = review.UserID,
         Header = review.Header,
         Type = review.Type,
         Text = review.Text,
         PublishTime = review.PublishTime,
     });
 }
Esempio n. 5
0
 public static ReviewModel ToReviewModel(this ServiceReview review, UserShortModel user, BookShortModel book)
 {
     return(new ReviewModel()
     {
         ID = review.ID,
         Book = book,
         Header = review.Header,
         PublishTime = review.PublishTime,
         Text = review.Text,
         Type =
             (review.Type < 0)
                 ? ReviewType.Negative
                 : review.Type == 0 ? ReviewType.Neutral : ReviewType.Positive,
         User = user,
     });
 }
Esempio n. 6
0
        public void TestInsertReview()
        {
            //ARRANGE
            ReviewControl control = new ReviewControl();
            ServiceReview review  = new ServiceReview();

            review.Comment = "Test Comment";
            review.Rating  = 3;
            int testId = 0;

            //ACT
            testId = control.InsertReview(review);

            //ASSERT
            Assert.IsTrue(testId > 0);
        }
Esempio n. 7
0
        public bool ServiceReviewCreate(ServiceReviewCreate model)
        {
            var entity = new ServiceReview()
            {
                ServiceReviewOwnerId = _srUserId,
                ServiceReviewTitle   = model.ServiceReviewTitle,
                ServiceReviewText    = model.ServiceReviewText,
                ServiceReviewStars   = model.ServiceReviewStars,
                CreatedUtc           = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.ServiceReviews.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 8
0
        public int InsertReview(ServiceReview review)
        {
            //Test purposes
            int insertedReviewId = -1;

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand cmdInsertReview = connection.CreateCommand())
                {
                    cmdInsertReview.CommandText = "INSERT INTO Review (rating, comment) OUTPUT INSERTED.reviewId VALUES (@rating, @comment)";
                    cmdInsertReview.Parameters.AddWithValue("rating", review.Rating);
                    cmdInsertReview.Parameters.AddWithValue("comment", review.Comment);
                    insertedReviewId = (int)cmdInsertReview.ExecuteScalar();
                }
            }
            return(insertedReviewId);
        }
Esempio n. 9
0
 public void RemoveReview(ServiceReview review)
 {
     unit.Reviews.Delete(review.ToDalReview());
     unit.Save();
 }
Esempio n. 10
0
 public void AddReview(ServiceReview review)
 {
     unit.Reviews.Create(review.ToDalReview());
     unit.Save();
 }
Esempio n. 11
0
 public void AddReview(ServiceReview review)
 {
     _context.ServiceReviews.Add(review);
 }
Esempio n. 12
0
 public int InsertReview(ServiceReview review)
 {
     return(reviewControl.InsertReview(review));
 }
Esempio n. 13
0
 public int InsertReview(ServiceReview review)
 {
     return(dataReview.InsertReview(review));
 }