public async Task <IActionResult> Create([Bind("ID,Type,Title,Price,TargetMonth,CreateDate,Status")] Transaction transaction) { if (ModelState.IsValid) { _context.Add(transaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(transaction)); }
public int Create(T entity) { _context.Add(entity); int RetVal = Save(); return(RetVal); }
public async Task <IActionResult> Create([Bind("Id,Phone,PurchaseDate,Price")] Transaction transaction) { if (ModelState.IsValid) { _context.Add(transaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(transaction)); }
public async Task <IActionResult> Create([Bind("TransactionID,TransactionType,AccountNumber,DestAccount,Amount,Comment,ModifyDate")] Transaction transaction) { if (ModelState.IsValid) { _context.Add(transaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(transaction)); }
// Post request sent when user submits the registration form. public IActionResult Register(User user) { // First check to see whether the form submitted was valid and meets all Model requirements. if (ModelState.IsValid) { // If the form was valid but the email submitted is already in the Db, this will catch the error. if (dbContext.Users.Any(u => u.Email == user.Email)) { ModelState.AddModelError("Email", "Email already in use!"); // Return the "Register" cshtml file with error messages displayed. return(View("Register")); } // If the form is valid and email is not already in the Db. A new user will be created. else { // First the user's password will be hashed for security purposes. PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); // Open the Db connection and add the user object to the database. dbContext.Add(user); // Save the changes to the Db and close the connection. dbContext.SaveChanges(); // Set the User's custom UserID in session thus allowing them to enter the app without having to login each time. HttpContext.Session.SetInt32("UserId", user.UserId); // Redirect to the User's custom account method with their UserID as the parameter. return(RedirectToAction($"Account/{user.UserId}")); } } // If the model state is invalid the "Register" cshtml file will be rendered with error messages displayed. else { return(View("Register")); } }
internal override EntityDesignerViewModel LoadModel( SerializationResult serializationResult, Partition partition, string fileName, ISchemaResolver schemaResolver, ValidationController validationController, ISerializerLocator serializerLocator) { var docData = VSHelpers.GetDocData(PackageManager.Package, fileName) as IEntityDesignDocData; docData.CreateAndLoadBuffer(); EntityDesignerViewModel evm = null; var serializationContext = new SerializationContext(GetDirectory(partition.Store), fileName, serializationResult); var transactionContext = new TransactionContext(); transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext); using (var t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, true, transactionContext)) { var uri = Tools.XmlDesignerBase.Base.Util.Utils.FileName2Uri(fileName); var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(uri); evm = ModelTranslatorContextItem.GetEntityModelTranslator(context).TranslateModelToDslModel(null, partition) as EntityDesignerViewModel; if (evm == null) { serializationResult.Failed = true; } else { if (t.IsActive) { t.Commit(); } } } // Validate imported model if (!serializationResult.Failed && (validationController != null)) { validationController.Validate(partition, ValidationCategories.Load); } return(evm); }
public async Task <IActionResult> AddOrEdit([Bind("TransactionId,TransactionName,TransactionAmount")] Transaction transaction) { if (ModelState.IsValid) { if (transaction.TransactionId == 0) { _context.Add(transaction); } else { _context.Update(transaction); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(transaction)); }
internal override EntityDesignerViewModel LoadModel( SerializationResult serializationResult, Partition partition, string fileName, ISchemaResolver schemaResolver, ValidationController validationController, ISerializerLocator serializerLocator) { var docData = VSHelpers.GetDocData(PackageManager.Package, fileName) as IEntityDesignDocData; docData.CreateAndLoadBuffer(); EntityDesignerViewModel evm = null; var serializationContext = new SerializationContext(GetDirectory(partition.Store), fileName, serializationResult); var transactionContext = new TransactionContext(); transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext); using (var t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, true, transactionContext)) { var uri = Tools.XmlDesignerBase.Base.Util.Utils.FileName2Uri(fileName); var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(uri); evm = ModelTranslatorContextItem.GetEntityModelTranslator(context).TranslateModelToDslModel(null, partition) as EntityDesignerViewModel; if (evm == null) { serializationResult.Failed = true; } else { if (t.IsActive) { t.Commit(); } } } // Validate imported model if (!serializationResult.Failed && (validationController != null)) { validationController.Validate(partition, ValidationCategories.Load); } return evm; }
/// <summary> /// This method loads the DSL view model with the items in the artifact's C-Model. /// </summary> internal void ReloadModel(EntityDesignerViewModel viewModel) { var diagram = viewModel.GetDiagram(); if (diagram == null) { // empty DSL diagram return; } // get our artifact var artifact = EditingContextManager.GetArtifact(viewModel.EditingContext) as EntityDesignArtifact; Debug.Assert(artifact != null); var serializationResult = new SerializationResult(); var serializationContext = new SerializationContext(GetDirectory(viewModel.Store), artifact.Uri.LocalPath, serializationResult); var transactionContext = new TransactionContext(); transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext); var workaroundFixSerializationTransactionValue = false; if (viewModel.Store.PropertyBag.ContainsKey("WorkaroundFixSerializationTransaction")) { workaroundFixSerializationTransactionValue = (bool)viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"]; } try { // To fix performance issue during reload, we turn-off layout during "serialization". viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"] = true; using (var t = viewModel.Store.TransactionManager.BeginTransaction("ReloadModel", true, transactionContext)) { if (artifact.ConceptualModel() == null) { return; } DesignerModel.Diagram diagramModel = null; // If DiagramId is not string empty, try to get the diagram from the artifact. // There is a situation where we could not find the diagram given an ID (for example: EDMX Model's Diagram that is created by VS before SQL 11; // In that case, we assign temporary ID to the diagram and a new ID will be generated every time the model is reloaded.) // We could safely choose the first diagram since multiple diagrams feature didn't exist in VS prior to SQL11 release. if (!string.IsNullOrEmpty(diagram.DiagramId)) { diagramModel = artifact.DesignerInfo.Diagrams.GetDiagram(diagram.DiagramId); } if (diagramModel == null) { diagramModel = artifact.DesignerInfo.Diagrams.FirstDiagram; } if (diagramModel != null) { // Re-establish the xref between Escher conceptual model and DSL root model. // and between Escher Diagram model and DSL diagram model. Debug.Assert(viewModel.ModelXRef != null, "Why ModelXRef is null?"); if (viewModel.ModelXRef != null) { viewModel.ModelXRef.Add(artifact.ConceptualModel(), viewModel, viewModel.EditingContext); viewModel.ModelXRef.Add(diagramModel, diagram, viewModel.EditingContext); ModelTranslatorContextItem.GetEntityModelTranslator(viewModel.EditingContext) .TranslateModelToDslModel(diagramModel, viewModel.Partition); } } if (t.IsActive) { t.Commit(); } } } finally { viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"] = workaroundFixSerializationTransactionValue; } }