public async Task <ActionResult> ChangeFirst(ChangeFirstViewModel model) { if (!ModelState.IsValid) { return(View(model)); } /* * var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); * if (result.Succeeded) * { * var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); * if (user != null) * { * await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); * } * return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }); * } * AddErrors(result);*/ var userId = User.Identity.GetUserId(); using (var context = new E_Commerce.Models.AuctionsDB()) { var user = context.User.Find(userId); user.FirstName = model.FirstName; context.Entry(user).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeFirstSuccess })); }
public ActionResult OpenAdmin(int?page) { log.Info("Auction/OpenAdmin has been fired."); using (var context = new E_Commerce.Models.AuctionsDB()) { IEnumerable <E_Commerce.Models.auction> auctions = from auc in context.auction where auc.status == "READY" select auc; int pageSize = AdminParams.N; int pageNum = 1; if (page != null) { pageNum = (int)page; } auctions = auctions.OrderBy(s => s.createdAt); return(View(auctions.ToPagedList(pageNum, pageSize))); } }
public ActionResult ListOrders(int?page) { log.Info("Token/ListOrders has been fired."); var userId = User.Identity.GetUserId(); IEnumerable <E_Commerce.Models.tokenOrder> orders = null; using (var context = new E_Commerce.Models.AuctionsDB()) { orders = context.tokenOrder.Where(to => userId.Equals(to.idUser)); int pageSize = AdminParams.N; int pageNum = 1; if (page != null) { pageNum = (int)page; } orders = orders.OrderBy(s => s.id); return(View(orders.ToPagedList(pageNum, pageSize))); } }
public ActionResult ConfirmBuy(string package) { log.Info("Token/ConfirmBuy has been fired."); int numT = 0; string link = ""; if (package.Equals("1")) { link = "&package=1"; numT = AdminParams.S; } else if (package.Equals("2")) { link = "&package=2"; numT = AdminParams.G; } else { link = "&package=3"; numT = AdminParams.P; } ViewBag.link = link; ViewBag.package = package; E_Commerce.Models.User user = null; using (var con = new E_Commerce.Models.AuctionsDB()) { using (var trans = con.Database.BeginTransaction(IsolationLevel.Serializable)) { try { user = con.User.Find(User.Identity.GetUserId()); if (user != null) { //make token order var to = new tokenOrder() { id = Guid.NewGuid(), numTokens = numT, idUser = User.Identity.GetUserId(), status = "SUBMITTED", price = AdminParams.T * numT }; con.tokenOrder.Add(to); con.SaveChanges(); trans.Commit(); return(View(to)); } else { throw new Exception(); } } catch (Exception ex) { log.Error("Error with submitting token order"); trans.Rollback(); } } } return(RedirectToAction("ListOrders", "Token")); }
public ActionResult Index(string title = "", string priceLow = "", string priceHigh = "", string status = "", int page = 1, MessageInfo message = MessageInfo.NoMesage) { log.Info("Auction/Index has been fired."); CheckFinish(); ViewBag.StatusMessage = message == MessageInfo.ChangeSuccess ? "Successfully opened a auction." : message == MessageInfo.ChangeUnsuccess ? "Error, something went wrong." : message == MessageInfo.AuctionFinished ? "Error, the auction is not in the READY state." : message == MessageInfo.AuctionClosed ? "Auction has been successfully closed." : message == MessageInfo.AuctionOver ? "The auction has finished." : message == MessageInfo.BidSuccess ? "Your bid has been successfully placed." : message == MessageInfo.NoTokens ? "Not enough tokens." : message == MessageInfo.RequiredFields ? "All fields are required." : message == MessageInfo.SuccessCreation ? "Auction successfully created." : ""; //list all opened auctions //param search bool titleE = false; bool priceLowE = false; bool priceHIghE = false; bool statusE = false; bool minmax = false; if (title != "") { titleE = true; } if (priceLow != "") { priceLowE = true; } if (priceHigh != "") { priceHIghE = true; } if (status != "") { statusE = true; } if (priceLowE && priceHIghE) { minmax = true; } using (var context = new E_Commerce.Models.AuctionsDB()) { IEnumerable <E_Commerce.Models.auction> auctions = from auc in context.auction select auc; /* * if (statusE) * { * auctions = auctions.Where(a => a.status == status); * }*/ try { if (minmax) { auctions = auctions.Where(a => a.currentPrice <= Double.Parse(priceHigh) && a.currentPrice >= Double.Parse(priceLow)); } else if (priceLowE) { auctions = auctions.Where(a => a.currentPrice >= Double.Parse(priceLow)); } else if (priceHIghE) { auctions = auctions.Where(a => a.currentPrice <= Double.Parse(priceHigh)); } } catch (Exception e) { Console.WriteLine("Error parsing to double."); } if (titleE) { string[] titles = title.Split(' '); foreach (var word in titles) { auctions = auctions.Where(a => a.title.ToLower().Contains(word.ToLower())); } } //ne radi!? if (statusE) { /* * switch (status) { * case "READY": * auctions = auctions.Where(a => a.status=="READY "); * break; * case "COMPLETED": * auctions = auctions.Where(a => a.status=="COMPLETED "); * break; * case "OPENED": * auctions = auctions.Where(a => a.status=="OPENED "); * break; * }*/ if (status == "N") { Console.WriteLine("Nothing"); } else if (status == "R") { auctions = auctions.Where(a => a.status == "READY "); } else if (status == "C") { auctions = auctions.Where(a => a.status == "COMPLETED "); } else if (status == "O") { auctions = auctions.Where(a => a.status == "OPENED "); } } /* * IEnumerable<E_Commerce.Models.AuctionAndLastBidModel> model=null; * foreach(var auction in auctions) * { * //model.Add(auction,null); * }*/ int pageSize = AdminParams.N; int pageNum = 1; if (page != 1) { pageNum = (int)page; } auctions = auctions.OrderByDescending(s => s.title); ViewBag.sTitle = title; ViewBag.sStatus = status; ViewBag.sPriceLow = priceLow; ViewBag.sPriceHigh = priceHigh; ViewBag.sPage = pageNum; return(View(auctions.ToPagedList(pageNum, pageSize))); } }