public async Task <IActionResult> Create([Bind("Id,Name,Smarts,ImageFile,URL")] SustainableChemistryWeb.ViewModels.FunctionalGroupViewModel functionalGroupView) { if (ModelState.IsValid) { string name = System.IO.Path.GetFileName(functionalGroupView.ImageFile.FileName); FunctionalGroup appFunctionalGroup = new FunctionalGroup() { Name = functionalGroupView.Name, Smarts = functionalGroupView.Smarts, Image = "Images/FunctionalGroups/" + name, URL = functionalGroupView.URL }; if (functionalGroupView.ImageFile.Length > 0) { using (var stream = new System.IO.FileStream(_hostingEnvironment.WebRootPath + "/Images/FunctionalGroups/" + name, System.IO.FileMode.Create)) { await functionalGroupView.ImageFile.CopyToAsync(stream); stream.Close(); } } _context.Add(appFunctionalGroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(functionalGroupView)); }
public async Task <IActionResult> Create([Bind("Id,Name,ReactantA,ReactantB,ReactantC,Product,Heat,AcidBase,Image,CatalystId,FunctionalGroupId,SolventId,Url")] AppNamedreaction appNamedreaction) { if (appNamedreaction.Image != null && appNamedreaction.Image.Length > 0) { var file = System.IO.File.Open(appNamedreaction.Image, System.IO.FileMode.Open); appNamedreaction.Image = "Images/Reactions/" + System.IO.Path.GetFileName(file.Name); //There is an error here //var uploads = System.IO.Path.Combine(_appEnvironment.WebRootPath, "uploads\\img"); if (file.Length > 0) { var fileName = _hostingEnvironment.WebRootPath + "\\Images\\Reactions\\" + System.IO.Path.GetFileName(file.Name); using (var stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create)) { await file.CopyToAsync(stream); } } file.Close(); } if (ModelState.IsValid) { _context.Add(appNamedreaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CatalystId"] = new SelectList(_context.AppCatalyst, "Id", "Name", appNamedreaction.CatalystId); ViewData["FunctionalGroupId"] = new SelectList(_context.AppFunctionalgroup, "Id", "Name", appNamedreaction.FunctionalGroupId); ViewData["SolventId"] = new SelectList(_context.AppSolvent, "Id", "Name", appNamedreaction.SolventId); return(View(appNamedreaction)); }
public async Task <IActionResult> Create([Bind("Id,RISFile,ReactionId")] SustainableChemistryWeb.ViewModels.ReferenceCreateViewModel appReference) { if (ModelState.IsValid) { var tempReact = await _context.AppNamedreaction .Include(i => i.FunctionalGroup) .SingleOrDefaultAsync(i => i.Id == appReference.ReactionId); if (appReference.RISFile != null) { } appReference.Risdata = new System.IO.StreamReader(appReference.RISFile.OpenReadStream()).ReadToEnd(); SustainableChemistryWeb.Models.Reference reference = new Reference { FunctionalGroupId = tempReact.FunctionalGroupId, FunctionalGroup = tempReact.FunctionalGroup, ReactionId = appReference.ReactionId, Reaction = appReference.Reaction, Risdata = appReference.Risdata }; _context.Add(reference); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateReferenceData(null); return(View(appReference)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] SustainableChemistryWeb.Models.Reactant reactant) { try { Reactant appReactant = new Reactant() { Name = reactant.Name, Description = reactant.Description, Temp2 = string.Empty, }; if (string.IsNullOrEmpty(appReactant.Description)) { appReactant.Description = string.Empty; } if (ModelState.IsValid) { _context.Add(appReactant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Create([Bind("Id,Name,Smarts,Image")] AppFunctionalgroup appFunctionalgroup) { if (appFunctionalgroup.Image != null && appFunctionalgroup.Image.Length > 0) { var file = System.IO.File.Open(appFunctionalgroup.Image, System.IO.FileMode.Open); appFunctionalgroup.Image = "Images/FunctionalGroups/" + System.IO.Path.GetFileName(file.Name); //There is an error here //var uploads = System.IO.Path.Combine(_appEnvironment.WebRootPath, "uploads\\img"); if (file.Length > 0) { var fileName = _hostingEnvironment.WebRootPath + "\\Images\\FunctionalGroups\\" + System.IO.Path.GetFileName(file.Name); using (var stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create)) { await file.CopyToAsync(stream); } } file.Close(); } if (ModelState.IsValid) { _context.Add(appFunctionalgroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(appFunctionalgroup)); }
public async Task<IActionResult> Create([Bind("Id,Risdata,FunctionalGroupId,ReactionId")] AppReference appReference) { if (ModelState.IsValid) { _context.Add(appReference); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } ViewData["FunctionalGroupId"] = new SelectList(_context.AppFunctionalgroup, "Id", "Image", appReference.FunctionalGroupId); ViewData["ReactionId"] = new SelectList(_context.AppNamedreaction, "Id", "AcidBase", appReference.ReactionId); return View(appReference); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] SustainableChemistryWeb.Models.Catalyst catalyst) { try { Catalyst appCat = new Catalyst() { Name = catalyst.Name, Description = catalyst.Description }; if (ModelState.IsValid) { _context.Add(appCat); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Create([Bind("Id,Name,ReactantA,ReactantB,ReactantC,Product,Heat,AcidBase,ImageFile,CatalystId,FunctionalGroupId,SolventId,Url")] SustainableChemistryWeb.ViewModels.NamedReactionViewModel namedReactionView, string[] reactants, string[] byProducts) { NamedReaction appNamedreaction = new NamedReaction() { Name = namedReactionView.Name, ReactantA = string.Empty, ReactantB = string.Empty, ReactantC = string.Empty, Product = string.IsNullOrEmpty(namedReactionView.Product) ? string.Empty : namedReactionView.Product, Heat = namedReactionView.Heat, AcidBase = namedReactionView.AcidBase, //Image = "Images/Reactions/" + Guid.NewGuid().ToString() + namedReactionView.Image == null ? ".jpg" : , CatalystId = namedReactionView.CatalystId, FunctionalGroupId = namedReactionView.FunctionalGroupId, SolventId = namedReactionView.SolventId, Url = string.IsNullOrEmpty(namedReactionView.Url) ? string.Empty : namedReactionView.Url, }; if (namedReactionView.Image != null) { appNamedreaction.Image = "Images/Reactions/" + Guid.NewGuid().ToString() + System.IO.Path.GetFileName(namedReactionView.ImageFile.FileName); using (var stream = new System.IO.FileStream(_hostingEnvironment.WebRootPath + "/" + appNamedreaction.Image, System.IO.FileMode.Create)) { await namedReactionView.ImageFile.CopyToAsync(stream); stream.Close(); } } else { appNamedreaction.Image = "Images/Reactions/" + Guid.NewGuid().ToString() + ".jpg"; System.IO.StreamReader image = new System.IO.StreamReader(_hostingEnvironment.WebRootPath + "/Images/Reactions/th.jpg"); using (var stream = new System.IO.FileStream(_hostingEnvironment.WebRootPath + "/" + appNamedreaction.Image, System.IO.FileMode.Create)) { await image.BaseStream.CopyToAsync(stream); stream.Close(); } } if (reactants != null) { foreach (var reactant in reactants) { var reactantToAdd = new NamedReactionReactants { NamedreactionId = appNamedreaction.Id, ReactantId = long.Parse(reactant) }; appNamedreaction.AppNamedreactionReactants.Add(reactantToAdd); } } if (byProducts != null) { foreach (var reactant in byProducts) { var byProductToAdd = new NamedReactionByProducts { NamedreactionId = appNamedreaction.Id, ReactantId = long.Parse(reactant) }; appNamedreaction.AppNamedreactionByProducts.Add(byProductToAdd); } } if (ModelState.IsValid) { _context.Add(appNamedreaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateReactantData(appNamedreaction); return(View(appNamedreaction)); }