Beispiel #1
0
        public ActionResult Upload(ImageView imgView, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                if (files == null || files.ElementAt(0) == null || files.ElementAt(0).ContentLength == 0)
                {
                    ModelState.AddModelError("error", "Please, upload a file.");
                    return(View(imgView));
                }
                else
                {
                    var tmpExtraSeconds = 0;
                    foreach (var file in files)
                    {
                        string newImg = System.IO.Path.GetFileName(file.FileName);
                        string path   = System.IO.Path.Combine(
                            Server.MapPath("~/Images"), newImg);
                        if (newImg.ToLower().EndsWith(".jpg") || newImg.ToLower().EndsWith(".png"))
                        {
                            // file is uploaded
                            file.SaveAs(path);

                            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                            {
                                file.InputStream.CopyTo(ms);
                                byte[] array = ms.GetBuffer();
                            }

                            if (imgView.Image.Title == null)
                            {
                                imgView.Image.Title = "Title";
                            }
                            if (imgView.Image.Description == null)
                            {
                                imgView.Image.Description = "Description";
                            }

                            Image newImage = new Image()
                            {
                                ImageId     = Guid.NewGuid(),
                                FileName    = newImg,
                                Title       = imgView.Image.Title,
                                Description = imgView.Image.Description,
                                Comments    = new List <Comment>(),
                                CreateDate  = DateTime.Now.AddSeconds(tmpExtraSeconds)
                            };
                            Repo = GalleryRepositories.getRepo();
                            Repo.InsertImage(newImage, imgView.AlbumId);
                            tmpExtraSeconds += 5;
                        }
                    }
                }
            }
            return(RedirectToAction("OpenAlbum", "Album", new { albumId = imgView.AlbumId }));
        }
Beispiel #2
0
        public ActionResult AjaxGetImage(Guid id)
        {
            Repo = GalleryRepositories.getRepo();
            Image img = Repo.SelectImageByID(id);

            var result = new {
                ImageId     = img.ImageId,
                FileName    = img.FileName,
                Title       = img.Title,
                Description = img.Description,
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
 // GET: Admin/User
 public ActionResult Index()
 {
     Repo = GalleryRepositories.getRepo();
     return(View(Repo.SelectAllUsers()));
 }
Beispiel #4
0
 public AlbumController()
 {
     Repo = GalleryRepositories.getRepo();
 }