Exemple #1
0
        public ActionResult Create(Models.PhotoModel photo, HttpPostedFileBase file)
        {
            using (var context = new MvcDataContext())
            {
                // TODO: Add insert logic here

                if (photo != null)
                {
                    var phot = new PhotoClass();



                    phot.PhotoName = file.FileName;
                    phot.PhotoId   = Guid.NewGuid();
                    phot.Date      = DateTime.Now;
                    Path.GetFileName(file.FileName);
                    file.SaveAs(Path.Combine(Server.MapPath("~/Pictures"), file.FileName));
                    context.photo.Add(phot);
                    context.SaveChanges();
                }


                return(View());
            }
        }
Exemple #2
0
 public void UpdateBd(string photoName, int id)
 {
     Models.PhotoModel user = new Models.PhotoModel();
     using (var db = new PhotoDbContext())
     {
         var photo = db.Photos.Create();
         photo.PhotoPath = photoName;
         photo.AlbumId = id;
         db.Photos.Add(photo);
         db.SaveChanges();
     }
 }
Exemple #3
0
        public async Task <IActionResult> Save(Models.PhotoModel photo, IFormFile image)
        {
            if (photo == null)
            {
                return(NotFound("Photo not found."));
            }

            if (image.Length > 0)
            {
                var filePath = $"{_hostingEnvironment.WebRootPath}/Photos/{photo.Id}.jpg";
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await image.OpenReadStream().CopyToAsync(fileStream);
                }
                photo.TagList.ForEach(x => x = x.Trim().Trim('#'));
                DataSource.Instance.PhotoList.Add(photo);
            }
            return(RedirectToAction("Index"));
        }