Exemplo n.º 1
0
        public async Task <IActionResult> Miser(Enchere newEnchere)
        {
            var userManager = _serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
            var userName    = await userManager.FindByNameAsync(User.Identity.Name);

            Miseur miseur = (Miseur)userName;

            if (newEnchere.MiseMax < newEnchere.Niveau)
            {
                var nextMinBid = newEnchere.Niveau + (double)bidMove;
                ModelState.AddModelError(string.Empty, "Prochain montant d'enchère valide est:$" + nextMinBid);
                return(View(newEnchere));
            }


            var objet = await _context.Objets
                        .Include(o => o.Encheres)
                        .ThenInclude(o => o.Miseur)
                        .Include(o => o.ConfigurationAdmin)
                        .Include(o => o.Acheteur)
                        .Include(o => o.Vendeur)
                        .SingleOrDefaultAsync(m => m.ObjetID == newEnchere.ObjetId);

            var newMaxBid = newEnchere.MiseMax;
            //objet.ConfigurationAdmin = _context.ConfigurationAdmins.Last();

            var pas      = objet.ConfigurationAdmin.PasGlobalEnchere;
            var encheres = objet.Encheres.ToList();

            Double[] enchereTableau = new Double[encheres.Count];
            Miseur[] lesMiseurs     = new Miseur[encheres.Count];

            var i = 0;

            foreach (Enchere item in encheres)
            {
                enchereTableau[i] = item.MiseMax;
                lesMiseurs[i]     = item.Miseur;
                i++;
            }

            var bestBid = Max(enchereTableau);
            var newBid  = 0.00;

            var msgFr = "Un autre membre a surenchérit sur l'objet.Si vous n'augmentez pas votre enchère maximum vous perdrez l'objet";
            var msgEn = "Another member outbid the object .If you do not increase your maximum bid you will lose the item";
            var msg   = msgFr;

            if (newMaxBid > bestBid)
            {
                for (int j = 0; j < encheres.Count; j++)
                {
                    //Le système surenchérit automatiquement pour tous à l'enchère maximum.
                    encheres[j].Niveau = encheres[j].MiseMax;
                    //envoyerun message aux concernés les avisant q un autre mebre a surencherit sur l'objet

                    if (encheres[j].Miseur.Langue == "en")
                    {
                        msg = msgEn;
                    }
                    notifyBiders(miseur.Email, msg);
                }

                newBid = bestBid + (double)pas;
            }
            else
            {
                for (int j = 0; j < encheres.Count; j++)
                {
                    if (newMaxBid > encheres[j].MiseMax)
                    {
                        //Le système surenchérit automatiquement pour tous à l'enchère maximum.
                        encheres[j].Niveau = encheres[j].MiseMax;
                        //envoyerun message aux concernés les avisant q un autre mebre a surencherit sur l objet

                        if (encheres[j].Miseur.Langue == "en")
                        {
                            msg = msgEn;
                        }
                        notifyBiders(miseur.Email, msg);
                    }

                    if (newMaxBid <= encheres[j].MiseMax)
                    {
                        //Le système surenchérit automatiquement pour tous à l'enchère maximum.
                        encheres[j].Niveau = ((newMaxBid + (double)pas) < encheres[j].MiseMax) ? (newMaxBid + (double)pas) : encheres[j].MiseMax;

                        //on avise le miseur actuel selon sa langue parlée
                        if (encheres[j].Miseur.Langue == "en")
                        {
                            msg = msgEn;
                        }
                        notifyBiders(miseur.Email, msg);
                    }
                }
                newBid = newMaxBid;
            }

            Miseur losingBidder = lesMiseurs[index];

            objet.Fichiers = new List <Fichier>();

            newEnchere.Niveau  = newBid;
            newEnchere.MiseMax = newMaxBid;
            newEnchere.Miseur  = miseur;

            objet.Encheres.Add(newEnchere);
            _context.Update(objet);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public static void Initialize(IServiceProvider serviceProvider, IConfiguration Configuration)
        {
            var context = serviceProvider.GetRequiredService <ApplicationDbContext>();

            context.Database.EnsureCreated();

            //Ajout SB
            CreateRolesAdminUsers(serviceProvider, Configuration).Wait();

            if (!context.Categories.Any())
            {
                context.Categories.Add(new Categorie()
                {
                    Nom = "Home & Garden", Description = "Products For Home and Garden"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Jewellery & Watches", Description = "Jewellery & Watches"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Motors", Description = "Motors"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Sporting Goods", Description = "Sporting Goods"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Toys & Hobbies", Description = "Toys & Hobbies"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Fashion", Description = "Fashion"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Electronics", Description = "Electronics"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Convertible&Art", Description = "Convertible&Art"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Baby", Description = "Baby"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Book", Description = "Book"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Business & Industrial", Description = "Business & Industrial"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Camera & Photo", Description = "Camera & Photo"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Cell Phones & Accessories", Description = "Cell Phones & Accessories"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Cell Clothing,Shoes & Accessories", Description = "Clothing,Shoes & Accessories"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Computers,Tablets & Accessories", Description = "Computers,Tablets & Accessories"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Craft", Description = "Craft"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Heath & Beauty", Description = "Heath & Beauty"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Musical Instruments & Gears", Description = "Musical Instruments & Gears"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Gift Cards & Coupons", Description = "Gift Cards & Coupons"
                });
                context.Categories.Add(new Categorie()
                {
                    Nom = "Others Category", Description = "Others Category"
                });
                context.SaveChanges();
            }

            // Définir configuration admin ID
            if (!context.ConfigurationAdmins.Any())
            {
                context.ConfigurationAdmins.Add(new ConfigurationAdmin()
                {
                    TauxGlobalComissionAuVendeur = 5 / 100m, PasGlobalEnchere = 1
                });
                context.SaveChanges();
            }


            var UserManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();

            if (!context.Objets.Any())
            {
                // trouve un utilisateur pour le mettre vendeur
                ApplicationUser    user               = UserManager.Users.FirstOrDefault(p => p.UserName.Equals("*****@*****.**")); //changer "*****@*****.**" avec user.Email avec httpcontext.
                Vendeur            vendeur            = Mapper.Map <ApplicationUser, Vendeur>(user);                                            // conversion d'une entité User en Vendeur
                ConfigurationAdmin configurationAdmin = context.ConfigurationAdmins.FirstOrDefault(p => p.ConfigurationAdminId.Equals(1));


                context.Objets.Add(new Objet()
                {
                    Nom = "Sauder Kids Storage", Description = "Sauder Kids Storage Chest for Toys, Blankets, Clothes - Oiled Oak Finish", PrixDepart = 170d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/kidStorage.jpg", CategorieID = 1, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Men's Leather Watch", Description = "SEIKO SARB017 Mechanical Alpinist Automatic Men's Leather Watch - Made In Japan", PrixDepart = 480d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/LatherWatch.jpg", CategorieID = 2, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Professional Headlight Hands Free", Description = "Energizer Atex Hard Case Professional Headlight Hands Free Head Torch", PrixDepart = 30d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/HeadLight.jpg", CategorieID = 4, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Galaxy Baby Groot Figure", Description = "Guardians of The Galaxy Baby Groot Figure Flowerpot Style Pen Pot Xmas Gift", PrixDepart = 10d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/GardianGalaxy.jpg", CategorieID = 5, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Alcohol Breath Tester", Description = "LCD Digital Alcohol Breath Tester Breathalyzer Analyzer Detector Test AT6000", PrixDepart = 10d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/Alcoholtest.jpg", CategorieID = 7, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Sport Camera phones", Description = "Zhiyun Crane-M 3-Axis Gimbal Stabilizer for Mirrorless/Sport Camera phones", PrixDepart = 235d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/CameraPhone.jpg", CategorieID = 12, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Portable Play Yard", Description = "Funsport Portable Play Yard Black Arrow / playard / play pen for babies", PrixDepart = 85d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/BabyBed.jpg", CategorieID = 9, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Diary Notebook", Description = "Vintage Classic Retro Leather Journal Travel Notepad Blank Book Diary Notebook", PrixDepart = 10d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/Book.jpg", CategorieID = 10, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Dell Precision T5400", Description = "Dell Precision T5400 2 x Xeon Quad Core E5420 2.50Ghz 16GB RAM 500Gb HDD", PrixDepart = 200d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/Desktop.jpg", CategorieID = 15, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Abrasive Brush", Description = "OSBORN 32138  Grit Abrasive Brush great for log and wood home restore NIB", PrixDepart = 90d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/Brush.jpg", CategorieID = 11, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Hiking Camping Blade", Description = "New Pocket Fold Knife Sharp Outdoor Portable Travel Hiking Camping Blade Gift HY", PrixDepart = 10d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/Blade.jpg", CategorieID = 4, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.Objets.Add(new Objet()
                {
                    Nom = "Cord Craft Tool", Description = "0.8mm 78m/Roll Leather Hand Sewing Waxed Thread Hand Stitching Cord Craft Tool", PrixDepart = 10d, DateInscription = DateTime.Parse("2018-05-10"), DateLimite = DateTime.Parse("2018-06-04"), Status = Status.EnVente, imageUrl = "Uploads/Craft.jpg", CategorieID = 16, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                //objet sera vendu ( donc on le met tout de suite vendu comme raccourci)...
                context.Objets.Add(new Objet()
                {
                    Nom = "Cologne for Men", Description = "Azzaro Pour Homme Cologne for Men 100ml EDT Spray", PrixDepart = 10d, DateInscription = DateTime.Parse("2018-05-11"), DateLimite = DateTime.Parse("2018-05-12"), Status = Status.Vendu, imageUrl = "Uploads/Parfum.jpg", CategorieID = 17, Vendeur = vendeur, ConfigurationAdmin = configurationAdmin
                });
                context.SaveChanges();
            }

            // Par défaut, un vendeur place une première mise sur son objet correspondant au prix de départ (discutable... fait pour tester)
            if (!context.Encheres.Any())
            {
                Miseur miseur = (Miseur)UserManager.Users.FirstOrDefault(p => p.UserName.Equals("*****@*****.**"));

                Objet objet;
                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 1);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 2);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 3);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 4);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 5);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 6);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 7);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 8);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 9);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 10);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 11);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 12);
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });



                objet = context.Objets.FirstOrDefault(p => p.ObjetID == 13);

                // Mise par défaut placé par le vendeur
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });

                // Mise gagnante fait par l'admin ( [email protected] )
                context.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart + (double)objet.ConfigurationAdmin.PasGlobalEnchere, MiseMax = 15, Miseur = (Miseur)UserManager.Users.FirstOrDefault(p => p.UserName.Equals("*****@*****.**"))
                });

                // Enregistrer le prix de vente burte
                objet.PrixVenteBrute = objet.PrixDepart + (double)objet.ConfigurationAdmin.PasGlobalEnchere;

                // Enregistrer la commission sur cette vente
                objet.Commission = objet.PrixVenteBrute * (double)objet.ConfigurationAdmin.TauxGlobalComissionAuVendeur;

                // enregistré l'acheteur...
                objet.Acheteur = (Miseur)UserManager.Users.FirstOrDefault(p => p.UserName.Equals("*****@*****.**"));

                // Créer une évaluation d'achat fait par l'acheteur sur le vendeur (pour un objet vendu)
                objet.AchatEvaluation = new AchatEvaluation {
                    Vendeur = (Vendeur)UserManager.Users.FirstOrDefault(p => p.UserName.Equals("*****@*****.**")), Objet = objet, Commentaire = "Vendeur incompétent. Je ne ferai plus jamais affaire avec lui!", Cote = -3, DateEvaluation = DateTime.Now
                };

                // Créer une évaluation de vente fait par le vendeur sur l'acheteur (pour un objet vendu)
                objet.VenteEvaluation = new VenteEvaluation {
                    Acheteur = (Miseur)UserManager.Users.FirstOrDefault(p => p.UserName.Equals("*****@*****.**")), Objet = objet, Commentaire = "L'acheteur était très indécis et agressif lors de la transaction, mais il a quand même payé...", Cote = -1, DateEvaluation = DateTime.Now
                };

                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(AnnoncerObjectViewModel objetVM, IFormFile pic, IList <IFormFile> attachments)
        {
            if (ModelState.IsValid)
            {
                //validation supplémentaire
                if (objetVM.CategorieID == 1000)
                {
                    List <Categorie> CategoryList = new List <Categorie>();

                    CategoryList = (from categorie in _context.Categories select categorie).ToList();
                    CategoryList.Insert(0, new Categorie {
                        CategorieId = 1000, Nom = "Select"
                    });
                    ViewBag.CategoryList = CategoryList;

                    ViewData["CategorieID"] = new SelectList(_context.Categories, "Nom", "Nom");

                    ModelState.AddModelError("", "Select Category");
                    return(View(objetVM));
                } //fin validation sup

                Objet objet = Mapper.Map <AnnoncerObjectViewModel, Objet>(objetVM);

                // Affectation des autres propriétés requise... (Vendeur, Miseur, DateInscription, imageUrl, ConfigurationAdmin, Categorie, List d'enchere et Liste de fichiers)
                var userManager = _serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                var userName    = await userManager.FindByNameAsync(User.Identity.Name);

                objet.Vendeur         = (Vendeur)userName;
                objet.DateInscription = DateTime.Now;


                if (pic != null)
                {
                    var file     = Path.GetFileName(pic.FileName);
                    var fileName = System.IO.Path.Combine(he.WebRootPath, "Uploads") + $@"\{file}";
                    pic.CopyTo(new FileStream(fileName, FileMode.Create));
                    objet.imageUrl = "Uploads/" + file;
                }

                //carles
                foreach (IFormFile item in attachments)
                {
                    if (item != null)
                    {
                        var attachmentfile     = Path.GetFileName(item.FileName);
                        var attachmentFileName = System.IO.Path.Combine(he.WebRootPath, "Attachments") + $@"\{attachmentfile}";
                        item.CopyTo(new FileStream(attachmentFileName, FileMode.Create));
                        objet.Fichiers = new List <Fichier>();
                        objet.Fichiers.Add(new Fichier()
                        {
                            NomOriginal = attachmentfile, NomLocale = attachmentFileName, verseLe = DateTime.Now
                        });
                    }
                }

                objet.Categorie          = _context.Categories.FirstOrDefault(p => p.CategorieId == objetVM.CategorieID);
                objet.ConfigurationAdmin = _context.ConfigurationAdmins.Last();
                objet.Encheres           = new List <Enchere>();
                // objet.Fichiers = new List<Fichier>();

                //Affectation d'une 1e mise.. (Par défaut celui qui crée un objet place une première mise sur son objet, comme ça il est facturé si jamais personne mise et il "remporte" son objet)
                Miseur miseur = (Miseur)userName;
                objet.Encheres.Add(new Enchere()
                {
                    Objet = objet, Niveau = objet.PrixDepart, MiseMax = objet.PrixDepart, Miseur = miseur
                });
                // Fin affection 1e mise


                // Fin affectation des autres propriétés requises

                //Ajout à la BD de l'Objet à vendre ainsi qu'une première mise par défaut
                _context.Add(objet);
                await _context.SaveChangesAsync();

                //Fin ajout BD

                //Ajout Arash pour mettre objet en status Vendu apres certain temp !!!!!!!!!!!!!! ces ligne du code doit être exactement ici !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                BackgroundJob.Schedule(() => ChangeStatus(objet.ObjetID), objet.DateLimite);


                TempData["message"] = $"Objet '{objet.Nom}' has been created for bidding starting now and ending at '{objet.DateLimite}'.";
                return(RedirectToAction(nameof(Index)));
            }

            foreach (var modelState in ViewData.ModelState.Values)
            {
                foreach (var error in modelState.Errors)
                {
                }
            }

            return(View(objetVM));
        }