Пример #1
0
        public ActionResult AboutEdit(About about, HttpPostedFileBase image, int aboutId)
        {
            About aboutPhoto = _aboutRepository.GetAbout().FirstOrDefault(p => p.AboutId == aboutId);

            if (ModelState.IsValid)
            {
                    if (image != null)
                    {
                        about.ImageMimeType = image.ContentType;
                        about.ImageData = new byte[image.ContentLength];
                        image.InputStream.Read(about.ImageData, 0, image.ContentLength);
                    }
                    else
                    {
                        if (aboutPhoto != null)
                        {
                            about.ImageMimeType = aboutPhoto.ImageMimeType;
                            about.ImageData = aboutPhoto.ImageData;
                        }
                    }
                    _aboutRepository.SaveAbout(about);
                    TempData["message"] = string.Format("{0} Išsaugota", about.Title);
                    return RedirectToAction("About");
                }
            else
            {
                return View(about);
            }
        }
Пример #2
0
 public void SaveAbout(About about)
 {
     if (about.AboutId == 0)
     {
         _context.Abouts.Add(about);
     }
     else
     {
         About dbEntry = _context.Abouts.Find(about.AboutId);
         if (dbEntry != null)
         {
             dbEntry.Title = about.Title;
             dbEntry.SubTitle = about.SubTitle;
             dbEntry.ImageData = about.ImageData;
             dbEntry.ImageMimeType = about.ImageMimeType;
         }
     }
     _context.SaveChanges();
 }