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);
        }
 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");
     }
 }
 public void DeletePhoto(Photo p)
 {
     context.Photos.Remove(p);
     context.SaveChanges();
 }