예제 #1
0
        public void TestGetId()
        {
            var result = _mockRepo.GetById(4);

            Assert.IsNotNull(result);
            var article       = result.Result;
            var articleExpect = new DTOArticle()
            {
                Id          = 4,
                ImageSource = null,
                SellerId    = 1,
                State       = "free",
                Name        = "Jolies chaussures",
                Description = "",
                Category    = "shoes",
                Sex         = "woman",
                Brand       = "Converse",
                Condition   = 10,
            };

            Assert.AreEqual(articleExpect.Id, article.Id);
            Assert.AreEqual(articleExpect.ImageSource, article.ImageSource);
            Assert.AreEqual(articleExpect.SellerId, article.SellerId);
            Assert.AreEqual(articleExpect.State, article.State);
            Assert.AreEqual(articleExpect.Name, article.Name);
            Assert.AreEqual(articleExpect.Description, article.Description);
            Assert.AreEqual(articleExpect.Category, article.Category);
            Assert.AreEqual(articleExpect.Sex, article.Sex);
            Assert.AreEqual(articleExpect.Brand, article.Brand);
        }
예제 #2
0
        /// <summary>
        /// Converts a database entity to a dto entity list
        /// </summary>
        /// <param name="userModels">The user list to convert</param>
        /// <returns>the converted user list</returns>
        public static List <DTOArticle> DBOTODTOList(IEnumerable <Article> articleModels)
        {
            List <DTOArticle> result = new List <DTOArticle>();

            foreach (var articleModel in articleModels)
            {
                var article = new DTOArticle();

                article.Id          = articleModel.Id;
                article.ImageSource = articleModel.ImageSource;
                article.SellerId    = articleModel.SellerId;
                article.State       = articleModel.State;
                article.Name        = articleModel.Name;
                article.Price       = articleModel.Price;
                article.Description = articleModel.Description;
                article.Category    = articleModel.Category;
                article.Sex         = articleModel.Sex;
                article.Brand       = articleModel.Brand;
                article.Condition   = articleModel.Condition;
                article.CreatedAt   = articleModel.CreatedAt;

                result.Add(article);
            }

            return(result);
        }
예제 #3
0
        public void TestInsertOk()
        {
            var articleExpect = new DTOArticle()
            {
                Id          = 9,
                ImageSource = null,
                SellerId    = 1,
                State       = "free",
                Name        = "Joli pantalon",
                Description = "joli pantalon militaire",
                Category    = "pants",
                Sex         = "man",
                Brand       = null,
                Condition   = 6
            };

            var result  = _mockRepo.Insert(articleExpect).Result;
            var article = _mockRepo.GetById(9).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(articleExpect.Id, article.Id);
            Assert.AreEqual(articleExpect.ImageSource, article.ImageSource);
            Assert.AreEqual(articleExpect.SellerId, article.SellerId);
            Assert.AreEqual(articleExpect.State, article.State);
            Assert.AreEqual(articleExpect.Name, article.Name);
            Assert.AreEqual(articleExpect.Description, article.Description);
            Assert.AreEqual(articleExpect.Category, article.Category);
            Assert.AreEqual(articleExpect.Sex, article.Sex);
            Assert.AreEqual(articleExpect.Brand, article.Brand);
            var count = this._mockRepo.Count();

            Assert.AreEqual(9, _articles.Count);
        }
예제 #4
0
 public void EditArticleDTO(DTOArticle dtoeditarticle)
 {
     articleRepository.EditArticle(new Article
     {
         Id          = dtoeditarticle.Id,
         Title       = dtoeditarticle.Title,
         Category_Id = dtoeditarticle.Category_Id,
         PublishDate = dtoeditarticle.PublishDate,
         Tag         = dtoeditarticle.Tag,
         Note        = dtoeditarticle.Note,
         Attachment  = dtoeditarticle.Attachment
     }
                                   );
 }
        /// <summary>
        /// Show on a View which transaction have been noted
        /// </summary>
        /// <param name="CurrentarticleId"></param>
        /// <param name="sellername"></param>
        /// <returns>View with updated transactions note status</returns>
        public async Task <IActionResult> secondPageManager(long CurrentarticleId, string sellername)
        {
            var email = HttpContext.User.Identity.Name;
            var Buyer = _userRepo.GetUserByEmail(email);

            var transactionList   = new List <DTOArticle>();
            var Seller            = _userRepo.GetUserByUserName(sellername);
            var BuyerTransactions = await _transactionRepo.GetTransactionByUserId(Buyer.Id);

            foreach (var transaction in BuyerTransactions)
            {
                var toInsert       = new DTOArticle();
                var currentArticle = await _articleRepo.GetById(transaction.ArticleId);

                toInsert.Name  = currentArticle.Name;
                toInsert.State = currentArticle.State;
                toInsert.Id    = currentArticle.Id;
                if (toInsert.Transaction == null)
                {
                    toInsert.Transaction = new DTOTransaction();
                }
                var sellerToInsert = new DTOUserPublic();
                sellerToInsert.Name     = Seller.Name;
                sellerToInsert.UserName = Seller.UserName;
                toInsert.User           = sellerToInsert;

                if (currentArticle.Id == CurrentarticleId)
                {
                    toInsert.Transaction = transaction;

                    if (transaction.TransactionState == "sold")
                    {
                        toInsert.Transaction.TransactionState = "Sold and Noted";
                        transaction.TransactionState          = "Sold and Noted";
                    }
                    var upt = await _transactionRepo.Update(transaction);
                }
                else
                {
                    toInsert.Transaction.TransactionState = transaction.TransactionState;
                }

                transactionList.Add(toInsert);
            }

            ViewData["transactionlist"] = transactionList;

            return(View("Profile_secondPage"));
        }
        public async Task <IActionResult> Profile()
        {
            var          email        = HttpContext.User.Identity.Name;
            var          user         = _userRepo.GetUserByEmail(email);
            DTOLoginUser userToReturn = new DTOLoginUser();

            userToReturn.Name     = user.Name;
            userToReturn.Email    = user.Email;
            userToReturn.UserName = user.UserName;
            userToReturn.Address  = user.Address;
            userToReturn.Gender   = user.Gender;
            userToReturn.Note     = user.Note;
            userToReturn.NbNotes  = user.NbNotes;

            var transactionList = new List <DTOArticle>();

            var userTransactions = await _transactionRepo.GetTransactionByUserId(user.Id);

            foreach (var transaction in userTransactions)
            {
                var toInsert = new DTOArticle();
                var article  = await _articleRepo.GetById(transaction.ArticleId);

                toInsert.Name  = article.Name;
                toInsert.State = article.State;
                toInsert.Id    = article.Id;

                if (toInsert.Transaction == null)
                {
                    toInsert.Transaction = new DTOTransaction();
                    toInsert.Transaction.TransactionState = transaction.TransactionState;
                }


                var sellerFromDb = await _userRepo.GetById(article.SellerId);

                var sellerToInsert = new DTOUserPublic();
                sellerToInsert.Name     = sellerFromDb.Name;
                sellerToInsert.UserName = sellerFromDb.UserName;
                toInsert.User           = sellerToInsert;
                transactionList.Add(toInsert);
            }


            ViewData["transactionlist"] = transactionList;
            return(View(userToReturn));
        }
예제 #7
0
        /// <summary>
        /// converter
        /// </summary>
        /// <param name="article"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static DTOArticle DTOArticleEditionToArticle(DTOArticleEdition article, DTOUser user)
        {
            var newArticle = new DTOArticle();

            newArticle.Brand       = article.Brand;
            newArticle.Category    = article.Category;
            newArticle.Condition   = article.Condition;
            newArticle.State       = "Free";
            newArticle.CreatedAt   = DateTime.Now;
            newArticle.Description = article.Description;
            newArticle.ImageSource = article.ImageSource;
            newArticle.Name        = article.Name;
            newArticle.Price       = article.Price;
            newArticle.SellerId    = user.Id;
            newArticle.Sex         = article.Sex;
            newArticle.User        = DtoUserToDtoUserPublic(user);
            return(newArticle);
        }
예제 #8
0
        /// <summary>
        /// Converts a database entity to a dto entity
        /// </summary>
        /// <param name="user">The user to convert</param>
        /// <returns>the converted user</returns>
        public static Article DTOToDBO(DTOArticle articleModel)
        {
            var article = new Article();

            article.Id          = articleModel.Id;
            article.ImageSource = articleModel.ImageSource;
            article.SellerId    = articleModel.SellerId;
            article.State       = articleModel.State;
            article.Name        = articleModel.Name;
            article.Price       = articleModel.Price;
            article.Description = articleModel.Description;
            article.Category    = articleModel.Category;
            article.Sex         = articleModel.Sex;
            article.Brand       = articleModel.Brand;
            article.Condition   = articleModel.Condition;
            article.CreatedAt   = articleModel.CreatedAt;

            return(article);
        }
예제 #9
0
        public void TestUpdateWrongSellerId()
        {
            var updateUser = new DTOArticle
            {
                Id          = 9,
                ImageSource = "path-to-photo",
                SellerId    = 1,
                State       = "free",
                Name        = "Lunettes noires",
                Description = "Ray Ban noires",
                Category    = "accessories",
                Sex         = "woman",
                Brand       = "RayBan",
                Condition   = 10
            };
            var result = _mockRepo.Update(updateUser).Result;

            Assert.IsNull(result);
            Assert.AreEqual(8, _mockRepo.Count().Result);
        }
예제 #10
0
        public void TestInsertWrongUserId()
        {
            var article = new DTOArticle()
            {
                Id          = 6,
                ImageSource = null,
                SellerId    = 2,
                State       = "free",
                Name        = null,
                Description = "joli pantalon militaire",
                Category    = "pants",
                Sex         = "man",
                Brand       = null,
                Condition   = 6
            };
            var result = _mockRepo.Insert(article).Result;

            Assert.IsNull(result);
            var count = this._mockRepo.Count();

            Assert.AreEqual(8, count.Result);
        }
예제 #11
0
        public void TestUpdateOk()
        {
            var article = new DTOArticle()
            {
                Id          = 8,
                ImageSource = "path-to-photo",
                SellerId    = 1,
                State       = "free",
                Name        = "Lunettes noires",
                Description = "Ray Ban noires",
                Category    = "accessories",
                Sex         = "woman",
                Brand       = "RayBan",
                Condition   = 10,
                CreatedAt   = DateTime.Now
            };

            var result = _mockRepo.Update(article).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(article.Id, result.Id);
            Assert.AreEqual(article.Description, result.Description);
        }
        public async Task <IActionResult> NoteUser()
        {
            var email = HttpContext.User.Identity.Name;
            var Buyer = _userRepo.GetUserByEmail(email);


            var transactionList   = new List <DTOArticle>();
            var SellerName        = Request.Form["id"].ToString();
            var Seller            = _userRepo.GetUserByUserName(SellerName);
            var BuyerTransactions = await _transactionRepo.GetTransactionByUserId(Buyer.Id);

            var articleId = (long)Convert.ToDouble(Request.Form["articleId"].ToString());

            foreach (var transaction in BuyerTransactions)
            {
                var toInsert       = new DTOArticle();
                var currentArticle = await _articleRepo.GetById(transaction.ArticleId);

                toInsert.Name  = currentArticle.Name;
                toInsert.State = currentArticle.State;
                toInsert.Id    = currentArticle.Id;

                if (toInsert.Transaction == null)
                {
                    toInsert.Transaction = new DTOTransaction();
                }
                var sellerToInsert = new DTOUserPublic();
                sellerToInsert.Name     = Seller.Name;
                sellerToInsert.UserName = Seller.UserName;
                toInsert.User           = sellerToInsert;

                if (currentArticle.Id == articleId)
                {
                    toInsert.Transaction = transaction;

                    if (transaction.TransactionState == "sold")
                    {
                        toInsert.Transaction.TransactionState = "Sold and Noted";
                        transaction.TransactionState          = "Sold and Noted";
                    }
                    var upt = await _transactionRepo.Update(transaction);

                    var note = Convert.ToDouble(Request.Form["note"]);
                    Seller.NbNotes += 1;
                    Seller.Note     = FindNoteAverage(note, Seller.NbNotes);
                    var test = await _userRepo.Update(Seller);

                    if (test == null)
                    {
                        View("Cart", "Failed");
                    }
                }
                else
                {
                    toInsert.Transaction.TransactionState = transaction.TransactionState;
                }


                transactionList.Add(toInsert);
            }

            ViewData["transactionlist"] = transactionList;

            return(RedirectToAction("secondPageManager", new { CurrentarticleId = articleId, sellername = SellerName }));
        }