예제 #1
0
        // GET: Auction/BanUser
        public ActionResult BanUser(int iduser, int idpro)
        {
            dynamic emailkick = new Email("Kick");

            using (var ctx = new AuctionSiteDBEntities())
            {
                //get product
                var pro  = ctx.Products.Where(p => p.ID == idpro).FirstOrDefault();
                var user = ctx.Users.Where(u => u.ID == iduser).FirstOrDefault();
                var ban  = new BannedUser()
                {
                    IDProduct = idpro,
                    IDUser    = iduser,
                };
                //get onwer
                Auction currentowner = ctx.Auctions.Where(a => a.own == true && a.IDPro == idpro).FirstOrDefault();
                //create an email
                emailkick.To      = CurrentContext.GetCurUser().Email;
                emailkick.Name    = user.Name;
                emailkick.ProName = pro.Name;
                emailkick.Send();
                ctx.BannedUsers.Add(ban);
                ctx.SaveChanges();
                //check if we dont kick the onwer
                if (currentowner.IDUser != user.ID)
                {
                    return(RedirectToAction("SettedBid", "Auction", new { id = idpro }));
                }
            }
            using (var update = new AuctionSiteDBEntities())
            {
                var currentowner = update.Auctions.Where(a => a.own == true && a.IDPro == idpro).FirstOrDefault();
                currentowner.own = false;
                var secondMax = update.Auctions.OrderByDescending(a => a.MaxPrice)
                                .Where(p => p.IDPro == idpro)
                                .Skip(1).FirstOrDefault();
                //more than 1 price setting
                if (secondMax != null)
                {
                    secondMax.own = true;
                    //udpate maxprice of product
                    Product pro = update.Products.Where(p => p.ID == idpro).FirstOrDefault <Product>();
                    pro.PriceDisplay = secondMax.MaxPrice;
                    pro.lastuser     = secondMax.IDUser;
                    update.SaveChanges();
                }
                //if we just have 1 setting price for this product then second will be turnned into null
                else
                {
                    //udpate maxprice of product
                    Product pro = update.Products.Where(p => p.ID == idpro).FirstOrDefault <Product>();
                    pro.PriceDisplay = pro.StartPrice;
                    pro.lastuser     = null;
                    update.SaveChanges();
                }
            }
            return(RedirectToAction("SettedBid", "Auction", new { id = idpro }));
        }
예제 #2
0
        public ActionResult Register(RegisterVM model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ErrorMsg = "Incorrect CAPTCHA code!";
            }
            else
            {
                User u = new User
                {
                    Username   = model.f_Username,
                    Email      = model.f_Email,
                    Name       = model.f_Name,
                    Address    = model.f_Address,
                    Password   = StringUtils.Md5(model.f_RawPassword),
                    Permission = 0,
                    DOB        = DateTime.ParseExact(model.f_DOB, "d/M/yyyy", null)
                };

                using (var ctx = new AuctionSiteDBEntities())
                {
                    ctx.Users.Add(u);
                    ctx.SaveChanges();
                }
            }
            return(View());
        }
예제 #3
0
        public ActionResult ChangePassword(User vm)
        {
            using (var dt = new AuctionSiteDBEntities())
            {
                string encPwd = StringUtils.Md5(vm.Password);
                var    list   = dt.Users.ToList();
                var    user   = dt.Users.Where(u => u.Password == encPwd && vm.ID == u.ID).FirstOrDefault();
                if (user == null)
                {
                    ViewBag.ErrorMsg = "Current password is wrong!!!";
                    return(View(CurrentContext.GetCurUser()));
                }
                if (vm.NewPassword != vm.NewPasswordAgain)
                {
                    ViewBag.ErrorMsg = "Check your new password!!!";
                    return(View(CurrentContext.GetCurUser()));
                }
            }

            using (var ctx = new AuctionSiteDBEntities())
            {
                var user = ctx.Users.Where(u => u.ID == vm.ID).FirstOrDefault <User>();
                user.Password = StringUtils.Md5(vm.NewPassword);
                ctx.SaveChanges();
                ViewBag.ErrorMsg = "Change Password success!!!";
                return(View(CurrentContext.GetCurUser()));
            }
        }
예제 #4
0
        public ActionResult ChangeInfo(User vm)
        {
            using (var dt = new AuctionSiteDBEntities())
            {
                string encPwd = StringUtils.Md5(vm.Password);
                var    list   = dt.Users.ToList();
                var    user   = dt.Users.Where(u => u.Password == encPwd && vm.ID == u.ID).FirstOrDefault();
                if (user == null)
                {
                    ViewBag.ErrorMsg = "wrong password!!!";
                    return(View(CurrentContext.GetCurUser()));
                }
                if (list.Any(u => u.Email == vm.Email && u.ID != vm.ID))
                {
                    ViewBag.ErrorMsg = "this email has been already used ";
                    return(View(CurrentContext.GetCurUser()));
                }
            }

            int id = CurrentContext.GetCurUser().ID;

            using (var ctx = new AuctionSiteDBEntities())
            {
                var user = ctx.Users.Where(u => u.ID == vm.ID).FirstOrDefault <User>();
                user.Email = vm.Email;
                user.Name  = vm.Name;
                ctx.SaveChanges();
                ViewBag.ErrorMsg = "Change info success!!!";
                return(View(CurrentContext.GetCurUser()));
            }
        }
예제 #5
0
        public ActionResult Add(Product vm, HttpPostedFileBase Firstimg, HttpPostedFileBase Secondimg
                                , HttpPostedFileBase Thirdimg)
        {
            using (var ctx = new AuctionSiteDBEntities())
            {
                vm.CurrentPrice    = null;
                vm.HighestKeeper   = null;
                vm.EvaluationPoint = null;
                vm.TimePost        = DateTime.Now;
                ctx.Products.Add(vm);
                ctx.SaveChanges();

                if (Firstimg != null && Firstimg.ContentLength > 0 && (Secondimg != null && Secondimg.ContentLength > 0) &&
                    (Thirdimg != null && Thirdimg.ContentLength > 0))
                {
                    string spDirPath     = Server.MapPath("~/Img/products");
                    string targetDirPath = Path.Combine(spDirPath, vm.ID.ToString());
                    Directory.CreateDirectory(targetDirPath);

                    string mainFileName = Path.Combine(targetDirPath, "main.jpg");
                    Firstimg.SaveAs(mainFileName);

                    string mainFileName2 = Path.Combine(targetDirPath, "main2.jpg");
                    Secondimg.SaveAs(mainFileName2);

                    string mainFileName3 = Path.Combine(targetDirPath, "main3.jpg");
                    Thirdimg.SaveAs(mainFileName3);
                }

                var list = ctx.Categories.ToList();
                ViewBag.Categories = list;
            }

            return(View());
        }
예제 #6
0
 // GET: Auction/Rating
 public ActionResult Rating(RatingVM vm)
 {
     using (var ctx = new AuctionSiteDBEntities())
     {
         int  idcurrent = CurrentContext.GetCurUser().ID;
         bool check     = ctx.Ratings.Any(r => r.IDUser == vm.ID && r.IDUserRating == idcurrent);
         if (check == true)
         {
             TempData["mess"] = "You Have already rated for this seller!!!";
             return(RedirectToAction("ShowWin", "Auction"));
         }
         int  id   = vm.ID;
         User user = ctx.Users.Where(u => u.ID == id).FirstOrDefault <User>();
         if (vm.negativePoint == -1)
         {
             user.negativePoint++;
         }
         else
         {
             user.positivePoint++;
         }
         //save rating
         var rating = new Rating()
         {
             IDUser       = vm.ID,
             IDUserRating = CurrentContext.GetCurUser().ID,
         };
         ctx.Ratings.Add(rating);
         ctx.SaveChanges();
     }
     TempData["mess"] = "Thanks for your rating!!!";
     return(RedirectToAction("ShowWin", "Auction"));
 }
예제 #7
0
        // GET: Account/AskPermission
        public ActionResult AskPermission()
        {
            var WaitingUser = new UsersAsking()
            {
                Username   = CurrentContext.GetCurUser().Username,
                Email      = CurrentContext.GetCurUser().Email,
                Name       = CurrentContext.GetCurUser().Name,
                AskingDate = DateTime.Now,
                IDUser     = CurrentContext.GetCurUser().ID,
            };

            using (var ctx = new AuctionSiteDBEntities())
            {
                var userwaiting = ctx.UsersAskings.Any(u => u.IDUser == WaitingUser.IDUser);
                if (userwaiting == true)
                {
                    ViewBag.exist = "You have already asked for selling permission for once!!!";
                }
                else
                {
                    ctx.UsersAskings.Add(WaitingUser);
                    ctx.SaveChanges();
                }
            }

            return(View());
        }
예제 #8
0
 // GET: Products/ByCat
 public ActionResult ByCat(int?id)
 {
     if (id.HasValue == false)
     {
         return(RedirectToAction("Index", "Home"));
     }
     using (var ctx = new AuctionSiteDBEntities())
     {
         //check expired
         var listpros = ctx.Products.Where(p => (DateTime.Now > System.Data.Entity.DbFunctions.AddDays(p.TimePost, p.IntervalTime)))
                        .ToList();
         if (listpros.Count > 0)
         {
             foreach (Product pro in listpros)
             {
                 dynamic emailforwinner        = new Email("win");
                 dynamic emailforonwer         = new Email("owner");
                 dynamic emailforonwer_notsell = new Email("notsell");
                 pro.Bought = true;
                 var user      = ctx.Users.Where(u => u.ID == pro.lastuser).FirstOrDefault();
                 var userowner = ctx.Users.Where(u => u.ID == pro.UserID).FirstOrDefault();
                 if (pro.lastuser != null)
                 {
                     //create emails
                     //for winnner
                     emailforwinner.To      = user.Email;
                     emailforwinner.Name    = user.Name;
                     emailforwinner.ProName = pro.Name;
                     emailforwinner.price   = pro.PriceDisplay;
                     emailforwinner.Send();
                     //for onwer
                     emailforonwer.To      = userowner.Email;
                     emailforonwer.Name    = userowner.Name;
                     emailforonwer.ProName = pro.Name;
                     emailforonwer.price   = pro.PriceDisplay;
                     emailforwinner.Send();
                 }
                 //if no one pay attention for products lastuser == null
                 //for onwer
                 emailforonwer_notsell.To      = userowner.Email;
                 emailforonwer_notsell.Name    = userowner.Name;
                 emailforonwer_notsell.ProName = pro.Name;
                 emailforonwer_notsell.Send();
             }
         }
         ctx.SaveChanges();
         bool list    = ctx.Products.Any(p => p.Bought == false && p.IDCat == id);
         var  listpro = ctx.Products.Where(p => p.Bought == false && p.IDCat == id).ToList();
         //check if no product is found because all of them have been deleted at check expired
         if (list == true)
         {
             return(View(listpro));
         }
         else
         {
             return(View(model: null));
         }
     }
 }
예제 #9
0
 public ActionResult Edit(Category vm)
 {
     using (var ctx = new AuctionSiteDBEntities())
     {
         var      list        = ctx.Categories.ToList();
         Category CattoUpdate = list.Where(c => c.ID == vm.ID).FirstOrDefault <Category>();
         CattoUpdate.Name = vm.Name;
         ctx.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
 }
예제 #10
0
 // Get: Accept
 public ActionResult Deny(User vm)
 {
     using (var ctx = new AuctionSiteDBEntities())
     {
         var user = new UsersAsking {
             ID = vm.ID
         };
         ctx.UsersAskings.Attach(user);
         ctx.UsersAskings.Remove(user);
         ctx.SaveChanges();
         return(RedirectToAction("WaitingUsers", "MAccount"));
     }
 }
예제 #11
0
        public ActionResult Delete(Category vm)
        {
            using (var ctx = new AuctionSiteDBEntities())
            {
                var cat = new Category {
                    ID = vm.ID
                };
                ctx.Categories.Attach(cat);
                ctx.Categories.Remove(cat);
                ctx.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #12
0
        public ActionResult Add(Category vm)
        {
            using (var ctx = new AuctionSiteDBEntities())
            {
                var cat = new Category()
                {
                    Name = vm.Name,
                };

                ctx.Categories.Add(cat);
                ctx.SaveChanges();
                return(RedirectToAction("Index", "MCategories"));
            }
        }
예제 #13
0
        public ActionResult Delete(User vm)
        {
            using (var ctx = new AuctionSiteDBEntities())
            {
                var user = new User {
                    ID = vm.ID
                };
                ctx.Users.Attach(user);
                ctx.Users.Remove(user);
                ctx.SaveChanges();

                return(View());
            }
        }
예제 #14
0
 public ActionResult EditDes(ProductVM vm)
 {
     using (var ctx = new AuctionSiteDBEntities())
     {
         var pro = ctx.Products.Where(p => p.ID == vm.ID).FirstOrDefault <Product>();
         pro.Description = HttpUtility.HtmlDecode(vm.Description);
         ctx.SaveChanges();
     }
     using (var dt = new AuctionSiteDBEntities())
     {
         var pro = dt.EditDes.Where(p => p.ID == vm.IDMain).FirstOrDefault <EditDe>();
         pro.Content = HttpUtility.HtmlDecode(vm.Descriptionchanges);
         dt.SaveChanges();
         return(RedirectToAction("InTime", "MProduct"));
     }
 }
예제 #15
0
        public ActionResult WatchList(Product vm)
        {
            using (var ctx = new AuctionSiteDBEntities())
            {
                var iduser = CurrentContext.GetCurUser().ID;
                var fr     = new FavoriteProduct()
                {
                    IDProducts = vm.ID,
                    IDUsers    = iduser,
                };

                ctx.FavoriteProducts.Add(fr);
                ctx.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #16
0
 public ActionResult Reset(User vm)
 {
     using (var ctx = new AuctionSiteDBEntities())
     {
         var  list         = ctx.Users.ToList();
         User usertoUpdate = list.Where(u => u.ID == vm.ID).FirstOrDefault <User>();
         usertoUpdate.Password = StringUtils.Md5(vm.Email);
         ctx.SaveChanges();
         //create an email
         dynamic resetpassword = new Email("resetpassword");
         resetpassword.To   = vm.Email;
         resetpassword.Name = vm.Name;
         resetpassword.Send();
         return(RedirectToAction("Delete", "MAccount"));
     }
 }
예제 #17
0
        public ActionResult Register(RegisterVM model)
        {
            using (var ctx = new AuctionSiteDBEntities())
            {
                var list = ctx.Users.ToList();
                if (list.Any(u => u.Email == model.f_Email))
                {
                    ViewBag.ErrorMsg = "this email has been already used ";
                    return(View());
                }
                if (list.Any(u => u.Username == model.f_Username))
                {
                    ViewBag.ErrorMsg = "this username has been already used ";
                    return(View());
                }
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ErrorMsg = "Incorrect CAPTCHA code!";
            }
            else
            {
                User u = new User
                {
                    IsBargain     = false,
                    AskingDate    = null,
                    positivePoint = 0,
                    negativePoint = 0,
                    Username      = model.f_Username,
                    Email         = model.f_Email,
                    Name          = model.f_Name,
                    Address       = model.f_Address,
                    Password      = StringUtils.Md5(model.f_RawPassword),
                    Permission    = 0,
                    DOB           = DateTime.ParseExact(model.f_DOB, "d/M/yyyy", null)
                };

                using (var ctx = new AuctionSiteDBEntities())
                {
                    ctx.Users.Add(u);
                    ctx.SaveChanges();
                }
            }
            ViewBag.suss = "Cheers! sign up successfully. Please login to keep track your works!!!";
            return(View());
        }
예제 #18
0
        public ActionResult Login(LoginVM model)
        {
            string encPwd = StringUtils.Md5(model.f_RawPassword);

            using (var ctx = new AuctionSiteDBEntities())
            {
                var user = ctx.Users.Where(u => u.Username == model.f_Username && u.Password == encPwd)
                           .FirstOrDefault();
                if (user != null)
                {
                    Session["isLogin"] = 1;
                    Session["user"]    = user;

                    if (model.Remember)
                    {
                        Response.Cookies["userId"].Value   = user.ID.ToString();
                        Response.Cookies["userId"].Expires = DateTime.Now.AddDays(7);
                    }

                    if (user.AskingDate != null)
                    {
                        if (user.AskingDate.Value.AddDays(7) < DateTime.Now)
                        {
                            var  list         = ctx.Users.ToList();
                            User usertoUpdate = list.Where(u => u.ID == user.ID).FirstOrDefault <User>();
                            usertoUpdate.Permission = 0;
                            ctx.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.ErrorMsg = "Login failed! check your information!!!";
                    return(View());
                }
            }
        }
예제 #19
0
        // Post: Accept
        public ActionResult Accept(User vm)
        {
            UsersAsking useras;

            using (var ctx = new AuctionSiteDBEntities())
            {
                useras = ctx.UsersAskings.Where(s => s.IDUser == vm.ID).FirstOrDefault <UsersAsking>();
                var  list         = ctx.Users.ToList();
                User usertoUpdate = list.Where(u => u.ID == vm.ID).FirstOrDefault <User>();
                usertoUpdate.Permission = 1;
                usertoUpdate.AskingDate = DateTime.Now;
                ctx.SaveChanges();
            }

            //Create new context for disconnected scenario
            using (var newContext = new AuctionSiteDBEntities())
            {
                newContext.Entry(useras).State = System.Data.Entity.EntityState.Deleted;

                newContext.SaveChanges();
            }
            return(RedirectToAction("WaitingUsers", "MAccount"));
        }
예제 #20
0
 // GET: Auction
 public ActionResult Index(BargainVM vm)
 {
     using (var ctx = new AuctionSiteDBEntities())
     {
         dynamic emailsetprice = new Email("setprice");
         var     list_product  = ctx.Products.ToList();
         var     list_auction  = ctx.Auctions.ToList();
         var     user          = CurrentContext.GetCurUser();
         var     pro           = ctx.Products.Where(p => p.ID == vm.ID).FirstOrDefault <Product>();
         //check if this user just set a price for this product
         if (vm.Price >= pro.EndPrice)
         {
             var ac = new Auction()
             {
                 IDPro    = pro.ID,
                 IDUser   = user.ID,
                 Username = user.Username,
                 Fullname = user.Name,
                 Time     = DateTime.Now,
                 MaxPrice = vm.Price,
                 own      = true,
             };
             pro.lastuser     = user.ID;
             pro.PriceDisplay = ac.MaxPrice;
             pro.Bought       = true;
             ctx.Auctions.Add(ac);
             ctx.SaveChanges();
             //create an email
             emailsetprice.To      = user.Email;
             emailsetprice.Name    = user.Name;
             emailsetprice.ProName = pro.Name;
             emailsetprice.price   = pro.PriceDisplay;
             emailsetprice.Send();
         }
         if (pro.lastuser != CurrentContext.GetCurUser().ID &&
             (vm.Price >= pro.PriceDisplay + pro.StepPrice))
         {
             //check if each product has been setted a price once
             if ((list_auction.Any(l => l.IDPro == pro.ID) == false))
             {
                 var ac = new Auction()
                 {
                     IDPro    = pro.ID,
                     IDUser   = user.ID,
                     Username = user.Username,
                     Fullname = user.Name,
                     Time     = DateTime.Now,
                     MaxPrice = vm.Price,
                     own      = true,
                 };
                 pro.lastuser     = user.ID;
                 pro.PriceDisplay = ac.MaxPrice;
                 ctx.Auctions.Add(ac);
                 ctx.SaveChanges();
                 //create an email
                 emailsetprice.To      = user.Email;
                 emailsetprice.Name    = user.Name;
                 emailsetprice.ProName = pro.Name;
                 emailsetprice.price   = pro.PriceDisplay;
                 emailsetprice.Send();
             }
             //check if we have many sets of price already
             else
             {
                 var takeowner = ctx.Auctions.Where(t => t.own == true && t.IDPro == pro.ID).FirstOrDefault();
                 var ac        = new Auction()
                 {
                     IDPro    = pro.ID,
                     IDUser   = user.ID,
                     Username = user.Username,
                     Fullname = user.Name,
                     Time     = DateTime.Now,
                     MaxPrice = vm.Price,
                 };
                 if (takeowner == null)
                 {
                     ac.own           = true;
                     pro.lastuser     = user.ID;
                     pro.PriceDisplay = ac.MaxPrice;
                     ctx.Auctions.Add(ac);
                     ctx.SaveChanges();
                     ViewBag.info = "successfully!!!";
                 }
                 else if (takeowner.MaxPrice < ac.MaxPrice)
                 {
                     ac.own = true;
                     //mark lastuser has set price for product
                     pro.lastuser     = user.ID;
                     pro.PriceDisplay = ac.MaxPrice;
                     takeowner.own    = false;
                     ctx.Auctions.Add(ac);
                     ctx.SaveChanges();
                     ViewBag.info = "successfully!!!";
                 }
                 //create an email
                 emailsetprice.To      = user.Email;
                 emailsetprice.Name    = user.Name;
                 emailsetprice.ProName = pro.Name;
                 emailsetprice.price   = pro.PriceDisplay;
                 emailsetprice.Send();
             }
         }
         else
         {
             ViewBag.info = "You just nailled a price for it";
         }
     }
     return(RedirectToAction("Details", "Products", new { id = vm.ID }));
 }