// GET: Auction/Create
 public ActionResult Create()
 {
     var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
     proxy.Open();
     ViewBag.CategoryId = new SelectList(proxy.GetAllCategories(), "Id", "Name");
     proxy.Close();
     return View();
 }
 // GET: Auction/Create
 public ActionResult WinAution()
 {
     ApplicationDbContext db = new ApplicationDbContext();
     var email = db.Users.Where(e => e.UserName == User.Identity.Name).FirstOrDefault().Email;
     var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
     proxy.Open();
     var items = proxy.GetMyWonAuctionsHistory(email);
     proxy.Close();
     db.Dispose();
     return View(items);
 }
        public ActionResult Special(string Id)
        {
            var keyword = Request["keyword"];
            ViewBag.Type = Id;
            List<Auction> items;

            var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
            proxy.Open();
            items = proxy.GetTopPriceAuctionsByCategory(Id, 0, 100).ToList();
            ViewData["groups"] = proxy.GetAllCategories().Select(e => e.Name).ToList();
            proxy.Close();
            return View(items);
        }
        // GET: Auction
        public ActionResult Index()
        {
            List<Auction> items;

            var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
            proxy.Open();
            ApplicationDbContext db = new ApplicationDbContext();
            var email = db.Users.Where(e => e.UserName == User.Identity.Name).FirstOrDefault().Email;
            items = proxy.GetMyAuctions(email).ToList();
            ViewData["groups"] = proxy.GetAllCategories().Select(e => e.Name).ToList();
            proxy.Close();
            db.Dispose();
            return View(items);
        }
 // GET: Auction/Details/5
 public ActionResult Details(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
     proxy.Open();
     Auction auction = proxy.GetAuction(id.Value);
     proxy.Close();
     if (auction == null)
     {
         return HttpNotFound();
     }
     return View(auction);
 }
 public ActionResult Detail(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
     proxy.Open();
     Auction auction = proxy.GetAuction(id.Value);
     List<Auction> relativeAutions = proxy.GetOpenAuctionsByUser(auction.Owner.Email, 0, 10).ToList();
     proxy.Close();
     if (auction == null)
     {
         return HttpNotFound();
     }
     ViewData["OtherAutions"] = relativeAutions;
     return View(auction);
 }
        public ActionResult Create([Bind(Include = "Id,BestBid,Description,Name,PhotoUrl,Price")] Auction auction)
        {
            if (ModelState.IsValid)
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var email = db.Users.Where(e => e.UserName == User.Identity.Name).FirstOrDefault().Email;
                var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
                proxy.Open();
                var cateId = int.Parse(Request["CategoryId"]);
                auction.CategoryId = cateId;
                auction.StartTime = DateTime.Now;
                auction.EndTime = DateTime.Now;
                auction.AutionStatus = AuctionStatus.New;
                proxy.AddNewAuction(email, auction);
                proxy.Close();
                return RedirectToAction("Index");
            }

            return View(auction);
        }
 public ActionResult Comment(string returnUrl)
 {
     var autionId = int.Parse(Request["Id"]);
     if (User.Identity.IsAuthenticated)
     {
         ApplicationDbContext db = new ApplicationDbContext();
         var email = db.Users.Where(e => e.UserName == User.Identity.Name).FirstOrDefault().Email;
         var cmt = Request["Comment"];
         var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
         proxy.Open();
         proxy.Comment(email, autionId, cmt);
         proxy.Close();
     }
     return Redirect(returnUrl);
 }
 public ActionResult Bid(string returnUrl)
 {
     var autionId = int.Parse(Request["Id"]);
     var user = Request["User"];
     var status = false;
     if (User.Identity.IsAuthenticated)
     {
         ApplicationDbContext db = new ApplicationDbContext();
         var email = db.Users.Where(e => e.UserName == user).FirstOrDefault().Email;
         var price = int.Parse(Request["Price"]);
         var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
         proxy.Open();
         status = proxy.Bid(email, price, autionId);
         proxy.Close();
     }
     return Redirect(returnUrl);
 }
 public ActionResult Start()
 {
     ApplicationDbContext db = new ApplicationDbContext();
     var email = db.Users.Where(e => e.UserName == User.Identity.Name).FirstOrDefault().Email;
     var startTime = DateTime.Parse(Request["StartTime"]);
     var endTime = DateTime.Parse(Request["EndTime"]);
     var id = int.Parse(Request["Id"]);
     var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
     proxy.Open();
     proxy.StartAuction(email, id, startTime, endTime);
     proxy.Close();
     db.Dispose();
     return RedirectToAction("Index");
 }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName,
                    PhoneNumber = model.PhoneNumber,
                    Email = model.Email};
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    // Call service to register with auction service database
                    var proxy = new AuctionServiceClient("BasicHttpBinding_IAuctionService");
                    proxy.Open();
                    await proxy.AddServiceUserAsync(new Services.Models.User() { UserName = user.UserName, Email = user.Email, PhoneNumber = user.PhoneNumber });
                    proxy.Close();

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    string msg = "Bạn đã đăng ký tài khoản tại SGUStore<br/>Vui lòng hoàn tất việc đăng ký của bạn <a href=\"" + callbackUrl + "\">tại đây</a>";
                    await UserManager.SendEmailAsync(user.Id, "SGUStore - Xác nhận đăng ký", msg);

                    return RedirectToAction("Confirm", new { Email = user.Email });
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }