public ActionResult Edit(PersonalInformation info)
 {
     try
     {
         var result = db.infos.Find(info.Id);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
예제 #2
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                var entity = new PersonalData {
                    SecretToYou = collection[nameof(PersonalData.SecretToYou)]
                };
                _context.Add(entity);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(Photo photo)
        {
            try
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    string             path = Server.MapPath("~/Uploading/Img/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    string fileName = file.FileName;
                    string filePath = path + fileName;
                    photo.ImageUrl = filePath;
                    file.SaveAs(filePath);
                }

                // TODO: Add update logic here
                if (photo.Id == 0)
                {
                    db.Photos.Add(photo);
                }
                else
                {
                    var result = db.Photos.Where(p => p.Id == photo.Id).FirstOrDefault();
                    result = photo;
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }