コード例 #1
0
        public JsonResult AddPhoto(int albumId)
        {
            if (Request.Files.AllKeys.Any())
            {
                var files = Request.Files;
                var date = DateTime.Now;

                int[] photosId = new int[files.Count];
                int current = 0;
                for (int i = 0, l = files.Count; i < l; i++)
                {
                    Photo p = new Photo()
                        {
                            albumId = albumId,
                            creatingDate = date,
                            MimeType = files[i].ContentType,
                            data = new byte[files[i].ContentLength]
                        };
                    files[i].InputStream.Read(p.data, 0, files[i].ContentLength);
                    photosId[current++] = repository.AddPhoto(p);
                }
                return Json(photosId);
            }
            else return Json(null);
        }
コード例 #2
0
 public int AddPhoto(Photo photo)
 {
     Album a = context.Albums.Where(al => al.id == photo.albumId).FirstOrDefault();
     if (a != null)
     {
         context.Photos.Add(photo);
         context.SaveChanges();
         return photo.id;
     }
     else
     {
         throw new Exception("Can't add photo to the album that not exist");
     }
 }
コード例 #3
0
 public void DeletePhoto(Photo p)
 {
     context.Photos.Remove(p);
     context.SaveChanges();
 }