public ActionResult Index() { if (Session["UserID"] == null) { //System.Web.Security.FormsAuthentication.GetAuthCookie() return(RedirectToAction("Login", "Authentication")); } IndexViewModel indexVM = new IndexViewModel(); #region Get Providers indexVM.Providers = new ProvidersViewModel(); using (Comessa5Context repository = factory.GetContext()) { var itemsInfo = repository.cprovider.OrderBy(provider => provider.priority); foreach (var providerInfo in itemsInfo) { ProviderViewModel providerVM = new ProviderViewModel { ID = providerInfo.id, Name = providerInfo.name, IsVisible = providerInfo.isVisible, TodaysDinner = (DateTime.Today.Year.Equals(providerInfo.dinnerLastModified.Year) && (DateTime.Today.DayOfYear.Equals(providerInfo.dinnerLastModified.DayOfYear))) ? providerInfo.dinnerText : null }; indexVM.Providers.Providers.Add(providerVM); } } #endregion return(View(indexVM)); }
public async Task <ActionResult> DeleteOrder(int ID) { using (Comessa5Context repository = factory.GetContext()) { var toRemove = repository.corder.Where(order => order.id == ID).SingleOrDefault(); if (toRemove == null) { return(Json(false)); } repository.corder.Remove(toRemove); await repository.SaveChangesAsync(); } // Delete the item in the database return(Json(true)); // or if there is an error, return Json(null); to indicate failure }
public async Task <ActionResult> GetItems(int providerID) { using (Comessa5Context repository = factory.GetContext()) { List <ItemViewModel> items = await(from citem item in repository.citem where item.providerId == providerID select new ItemViewModel { ID = item.id, Name = item.name, Price = item.price, Priority = item.priority }).ToListAsync(); return(PartialView("ItemsView", items.OrderBy(item => item.Priority))); } }
public ActionResult DoLogin(UserViewModel u) { if (ModelState.IsValid) { using (Comessa5Context repository = factory.GetContext()) { cuser dbUser = repository.cuser.Where(user => string.Equals(user.login, u.Name)).FirstOrDefault(); if (dbUser == null || !string.Equals(u.Password.CalculateMD5Hash(), dbUser.password, StringComparison.InvariantCultureIgnoreCase)) { ModelState.AddModelError("CredentialError", "Invalid Name or Password"); return(View("Login")); } Session["UserName"] = u.Name; Session["UserID"] = dbUser.id; Session["UserIDForOrders"] = -1; Session["IsAdmin"] = dbUser.isServer; FormsAuthentication.SetAuthCookie(u.Name, u.RememberMe); } return(RedirectToAction("Index", "Home")); } return(View("Login")); }
public async Task <ActionResult> SaveOrder(int itemID, int userID, decimal quantity, string comments) { //ToDo: check if it's possible to do that using 1 operation instead of 2 using EF //...or parse the whole citem as argument here using (Comessa5Context repository = factory.GetContext()) { citem item = repository.citem.Where(citem => citem.id == itemID).FirstOrDefault(); cuser server = repository.cuser.Where(cuser => cuser.isServer && !cuser.isMasterServer).FirstOrDefault(); repository.corder.Add(new corder { itemId = itemID, quantity = quantity, comment = comments, userId = userID, itemName = item.name, price = item.price, date = DateTime.Now, status = (int)OrderStatus.Ordered, sellerId = server == null ? -1 : server.id }); await repository.SaveChangesAsync(); } return(Json(true)); }
public async Task <ActionResult> GetPayments(int userID) { #region Get Payments DateTime paymentsOlderThan = DateTime.Now; paymentsOlderThan -= TimeSpan.FromHours(paymentsOlderThan.Hour); using (Comessa5Context repository = factory.GetContext()) { List <PaymentViewModel> payments = await(from payment in repository.vpayment where ((userID == -1 && payment.date > paymentsOlderThan) || payment.recipientId == userID || payment.senderId == userID) orderby payment.id descending select new PaymentViewModel { ID = payment.id, Value = payment.amount, Comment = payment.comment, SenderID = payment.senderId, RecipientID = payment.recipientId, SenderName = payment.senderName, RecipientName = payment.recipientName, Type = (PaymentType)payment.type, Date = payment.date } ).ToListAsync(); return(PartialView("PaymentsView", payments)); } #endregion }
public async Task <ActionResult> GetOrders(int userID) { List <OrderViewModel> orders = null; #region Get todays orders if (userID == -1) { DateTime ordersOlderThan = DateTime.Now; ordersOlderThan -= TimeSpan.FromHours(ordersOlderThan.Hour); //int id = (int)Session["UserID"]; using (Comessa5Context repository = factory.GetContext()) { orders = await repository.corder.Include("citem").Include("citem.cprovider").Include("cuser") .Where(order => order.date > ordersOlderThan) .OrderByDescending(order => order.citem.cprovider.id) .Select(orderInfo => new OrderViewModel { ID = orderInfo.id, ItemName = orderInfo.citem.name, ItemID = (int)orderInfo.itemId, Price = orderInfo.price, Quantity = orderInfo.quantity, Comment = orderInfo.comment, ProviderName = orderInfo.citem.cprovider.name, Status = (OrderStatus)orderInfo.status, UserName = orderInfo.cuser.name, UserID = orderInfo.userId ?? -1, ForCurrentUserOnly = false } ).ToListAsync(); } } #endregion #region get orders for current user else { using (Comessa5Context repository = factory.GetContext()) { orders = await repository.corder.Include("citem").Include("citem.cprovider").Include("cuser") .Where(order => order.userId == userID) .OrderByDescending(order => order.id) .Select(orderInfo => new OrderViewModel { ID = orderInfo.id, ItemName = orderInfo.citem.name, ItemID = (int)orderInfo.itemId, Price = orderInfo.price, Quantity = orderInfo.quantity, Comment = orderInfo.comment, ProviderName = orderInfo.citem.cprovider.name, Status = (OrderStatus)orderInfo.status, UserName = orderInfo.cuser.name, UserID = orderInfo.userId ?? -1, ForCurrentUserOnly = true, Date = orderInfo.date } ).ToListAsync(); } } #endregion return(PartialView("OrdersView", orders)); }