コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("BurialID,LowPairNS,HighPairNS,BurialLocationNS,LowPairEW,HighPairEW,BurialLocationEW,Area,ShaftNumber,BurialNumber,SouthToHeadInMeters,SouthToFeetInMeters,WestToHeadInMeters,WestToFeetInMeters,LengthInMeters,DepthInMeters,PhotoPath,BurialGoods,Hair,Age,BurialMaterials,ExcavationRecorder,Date,Time")] Exhumation exhumation)
        {
            if (id != exhumation.BurialID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(exhumation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExhumationExists(exhumation.BurialID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(exhumation));
        }
コード例 #2
0
        public IActionResult Create(ExhumationCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                //generate a unique file name (using Guid) for the photo being saved (so that it doesn't overwrite any already saved)
                //save photos in the img/Exhumations folder
                string uniqueFileName = null;
                if (model.Photo != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "img/Exhumations");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                //copy all the existing exhumation data, along with the newly created photopath, to a new exhumation entry
                Exhumation newExhumation = new Exhumation
                {
                    LowPairNS           = model.LowPairNS,
                    HighPairNS          = model.HighPairNS,
                    BurialLocationNS    = model.BurialLocationNS,
                    LowPairEW           = model.LowPairEW,
                    HighPairEW          = model.HighPairEW,
                    BurialLocationEW    = model.BurialLocationEW,
                    Area                = model.Area,
                    ShaftNumber         = model.ShaftNumber,
                    BurialNumber        = model.BurialNumber,
                    SouthToHeadInMeters = model.SouthToHeadInMeters,
                    SouthToFeetInMeters = model.SouthToFeetInMeters,
                    WestToHeadInMeters  = model.WestToHeadInMeters,
                    WestToFeetInMeters  = model.WestToFeetInMeters,
                    LengthInMeters      = model.LengthInMeters,
                    DepthInMeters       = model.DepthInMeters,
                    PhotoPath           = uniqueFileName,
                    BurialGoods         = model.BurialGoods,
                    Hair                = model.Hair,
                    Age                = model.Age,
                    BurialMaterials    = model.BurialMaterials,
                    ExcavationRecorder = model.ExcavationRecorder,
                    Date               = model.Date,
                    Time               = model.Time
                };

                //add the new entry to the database and save it
                _context.Exhumations.Add(newExhumation);
                _context.SaveChanges();

                //send the person to the details page of what they just created
                return(RedirectToAction("Details", new { id = newExhumation.BurialID }));
            }

            return(View());
        }