/// <summary> /// /// </summary> /// <param name="Session"></param> /// <param name="product">.Id must be valid</param> public static void product(TempDataDictionary TempData, Product product) { // Update Database Product db_product; using (FM_Datastore_Entities_EF db_manager = new FM_Datastore_Entities_EF()) { db_product = db_manager.Products.Include(AppSettings.Includes.Category).FirstOrDefault(m => m.Id == product.Id); if (db_product != null) { db_product.name = product.name; db_product.price = product.price; db_product.categoryId = product.categoryId; db_manager.Entry(db_product); db_manager.SaveChanges(); } } if (db_product != null) { db_product.Category = product.Category; // Update session List <Product> products; Load.products(TempData, out products); Product tmpProd = products.FirstOrDefault(m => m.Id == product.Id); if (tmpProd != null) { int indexTmpProd = products.IndexOf(tmpProd); products[indexTmpProd] = db_product; } // Update session combobox List <SelectListItem> productsCombobox; Load.productsCombobox(TempData, out productsCombobox); SelectListItem tmpSLI = productsCombobox.FirstOrDefault(m => m.Value == db_product.Id.ToString()); if (tmpSLI != null) { int indexTmpSLI = productsCombobox.IndexOf(tmpSLI); productsCombobox[indexTmpSLI] = new SelectListItem() { Text = db_product.name, Value = db_product.Id.ToString() }; } } }
/// <summary> /// /// </summary> /// <param name="Session"></param> /// <param name="category">.Id must be valid</param> public static void category(TempDataDictionary TempData, Category category) { Category db_category; // Update Database using (FM_Datastore_Entities_EF db_manager = new FM_Datastore_Entities_EF()) { db_category = db_manager.Categories.FirstOrDefault(m => m.Id == category.Id); if (db_category != null) { db_category.name = category.name; db_manager.Entry(db_category); db_manager.SaveChanges(); } } // Update session List <Category> categories; Load.categories(TempData, out categories); Category tmpCategory = categories.FirstOrDefault(m => m.Id == db_category.Id); if (tmpCategory != null) { int indexTmpProd = categories.IndexOf(tmpCategory); categories[indexTmpProd] = db_category; } // Update session combobox List <SelectListItem> productsCombobox; Load.categoriesCombobox(TempData, out productsCombobox); SelectListItem tmpSLI = productsCombobox.FirstOrDefault(m => m.Value == db_category.Id.ToString()); if (tmpSLI != null) { int indexTmpSLI = productsCombobox.IndexOf(tmpSLI); productsCombobox[indexTmpSLI] = new SelectListItem() { Text = db_category.name, Value = db_category.Id.ToString() }; } }
public static void transaction(HttpSessionStateBase Session, Transaction transaction) { // Update Database using (FM_Datastore_Entities_EF db_manager = new FM_Datastore_Entities_EF()) { db_manager.Entry(transaction); db_manager.SaveChanges(); } // Update session List <Transaction> transactions; Load.transactions(Session, out transactions, false); Transaction tmpTransaction = transactions.FirstOrDefault(m => m.Id == transaction.Id); if (tmpTransaction != null) { int indexTmpProd = transactions.IndexOf(tmpTransaction); transactions[indexTmpProd] = transaction; } // no combobox needed }
public ActionResult Notify(NotifyViewModel model, string submitButton, string id, long?Role) { if (User.IsInRole(AppSettings.Roles.APPROVEDUSER) || User.IsInRole(AppSettings.Roles.AUDITORS)) { return(new HttpNotFoundResult()); } if (model.Role == null) { return(View(model)); // redisplay the view if error } long role = (long)model.Role; if (Role != null) { role = (long)Role; } model.notifyList = (List <Notification>)Session["notifyListDB"]; model.Role = (long)Session["roleResult"]; model.Roles = (List <SelectListItem>)Session["RolesList"]; long result; if (!long.TryParse(id, out result)) { return(View(model)); } FM_Datastore_Entities_EF db_manager = new FM_Datastore_Entities_EF(); // get notification Notification oldNotify = db_manager.Notifications.FirstOrDefault(m => m.Id == result); switch (submitButton) { case "Resend Notification": //send email to new user Mail.send( oldNotify.Email, "Access Approved", "here is the link to sign up this link will only be available for so long - " + "https://" + HttpContext.Request.Url.Authority + Url.Action("Register", "Account") + "?rqst=" + UrlEncryption.Encrypt( DateTime.UtcNow, oldNotify.Email, oldNotify.AddressId, oldNotify.DivisionId, role)); ViewBagHelper.setMessage(ViewBag, ViewBagHelper.MessageType.SuccessMsgBox, "New user request resent to \"" + oldNotify.Email + "\""); return(NotifyView()); case "Accept": if (oldNotify.notifyType.Equals(AppSettings.Notify.newUser)) { //send email to new user Mail.send( oldNotify.Email, "Access Approved", "here is the link to sign up this link will only be available for so long - " + "https://" + HttpContext.Request.Url.Authority + Url.Action("Register", "Account") + "?rqst=" + UrlEncryption.Encrypt( DateTime.UtcNow, oldNotify.Email, oldNotify.AddressId, oldNotify.DivisionId, role)); oldNotify.notifyType = AppSettings.Notify.pendingUser; oldNotify.Role = db_manager.Roles.FirstOrDefault(m => m.Id == role).Name; db_manager.Entry(oldNotify); db_manager.SaveChanges(); db_manager.Dispose(); } return(NotifyView()); case "Deny": // send denial email to user Mail.send(oldNotify.Email, "Denied Access", "Appologies user you have been denied access by administration to the application."); model.notifyList.Remove(model.notifyList.First(m => m.Id == result)); // remove from current model db_manager.Notifications.Remove(oldNotify); break; default: break; } db_manager.SaveChanges(); db_manager.Dispose(); return(View(model)); }