public IHttpActionResult PutPortModel(int id, PortModel portModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != portModel.Id)
            {
                return(BadRequest());
            }

            db.Entry(portModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PortModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public IActionResult Edit(int?id, Section1 section, IFormFile Photo)
        {
            if (id == null)
            {
                return(NotFound());
            }
            //Image Upload
            string imgName    = Guid.NewGuid() + "_" + Photo.FileName;
            string uploadLink = Path.Combine(_env.WebRootPath, "uploads");
            string filePath   = Path.Combine(uploadLink, imgName);

            using FileStream file = new FileStream(filePath, FileMode.Create);
            Photo.CopyTo(file);
            section.PhotoUrl = imgName;
            _context.Section1.Update(section);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }