Beispiel #1
0
        public async Task<IActionResult> Edit(long id, [Bind("Id,Risdata,FunctionalGroupId,ReactionId")] AppReference appReference)
        {
            if (id != appReference.Id)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appReference);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppReferenceExists(appReference.Id))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                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> Edit(long id, [Bind("Id,Risdata, ReactionId")] SustainableChemistryWeb.ViewModels.ReferenceViewModel appReference)
        {
            if (id != appReference.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var referenceToUpdate = await _context.AppReference
                                        .Include(i => i.FunctionalGroup)
                                        .Include(i => i.Reaction)
                                        .SingleOrDefaultAsync(i => i.Id == id);

                var tempReact = await _context.AppNamedreaction
                                .Include(i => i.FunctionalGroup)
                                .SingleOrDefaultAsync(i => i.Id == appReference.ReactionId);

                if (await TryUpdateModelAsync <Reference>(
                        referenceToUpdate,
                        "",
                        r => r.ReactionId, r => r.Risdata))
                {
                    if (appReference.RISFile != null)
                    {
                        referenceToUpdate.Risdata = new System.IO.StreamReader(appReference.RISFile.OpenReadStream()).ReadToEnd();
                    }
                    referenceToUpdate.FunctionalGroupId = tempReact.FunctionalGroupId;
                    referenceToUpdate.FunctionalGroup   = tempReact.FunctionalGroup;
                }
                _context.Update(referenceToUpdate);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,Name,ReactantA,ReactantB,ReactantC,Product,Heat,AcidBase,Image,CatalystId,FunctionalGroupId,SolventId,Url")] AppNamedreaction appNamedreaction)
        {
            if (id != appNamedreaction.Id)
            {
                return(NotFound());
            }

            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)
            {
                try
                {
                    _context.Update(appNamedreaction);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppNamedreactionExists(appNamedreaction.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                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> Edit(long id, [Bind("Id,Name,Smarts,Image")] AppFunctionalgroup appFunctionalgroup)
        {
            if (id != appFunctionalgroup.Id)
            {
                return(NotFound());
            }

            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)
            {
                try
                {
                    _context.Update(appFunctionalgroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppFunctionalgroupExists(appFunctionalgroup.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(appFunctionalgroup));
        }