Пример #1
0
        public ActionResult GetPhoto(string userId, int galleryId, int photoId)
        {
            UserGalleryModel gallery = ApplicationDbContext.Create().Galleries
                                       .First(g => g.Owner.Id == userId && g.Id == galleryId);
            var pathbulider = new StringBuilder("~/Galleries/");
            var dir         = Server.MapPath(pathbulider.Append(userId).Append("/").Append(galleryId).ToString());
            var path        = Path.Combine(dir, gallery.PhotosList.Where(x => x.Id == photoId).Single().Path);

            Debug.WriteLine(path);
            return(base.File(path, "image/jpeg"));
        }
Пример #2
0
    //[POST("Gallery/")]
    public void Add([FromUri] string name)
    {
        var              db     = ApplicationDbContext.Create();
        string           userId = User.Identity.GetUserId();
        ApplicationUser  owner  = db.Users.Where(x => x.Id == userId).FirstOrDefault();
        UserGalleryModel model  = new UserGalleryModel(name, owner);

        db.Galleries.Add(model);
        db.SaveChanges();
        //return null;
    }
Пример #3
0
    public ActionResult Delete(int?id)
    {
        if (id == null)
        {
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
        var db = ApplicationDbContext.Create();
        UserGalleryModel entity = db.Galleries.Find(id);

        db.Galleries.Remove(entity);
        db.SaveChanges();
        return(RedirectToAction("GetAll"));
    }
Пример #4
0
    public ActionResult UserGallery(string userId, int?galleryId)
    {
        if (galleryId == null)
        {
            return(RedirectToAction("GetAll"));
        }
        ViewBag.galleryId = galleryId;
        ViewBag.userId    = userId;
        ApplicationDbContext db      = ApplicationDbContext.Create();
        ApplicationUser      user    = db.Users.Single(x => x.Id == userId);
        UserGalleryModel     gallery = db.Galleries.Single(x => x.Id == galleryId);

        return(View(gallery));
    }
Пример #5
0
 public ActionResult AddGallery([FromUri] string name)
 {
     try
     {
         var              db     = ApplicationDbContext.Create();
         string           userId = User.Identity.GetUserId();
         ApplicationUser  owner  = db.Users.Where(x => x.Id == userId).FirstOrDefault();
         UserGalleryModel model  = new UserGalleryModel(name, owner);
         db.Galleries.Add(model);
         db.SaveChanges();
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Пример #6
0
        public ActionResult UploadPhoto(int galleryId)
        {
            try
            {
                var db = ApplicationDbContext.Create();
                var id = User.Identity.GetUserId();
                UserGalleryModel gallery =
                    db.Galleries.First(g => g.Owner.Id == id && g.Id == galleryId);
                var pathbulider = new StringBuilder("~/Galleries/");
                var dir         = Server.MapPath(pathbulider.Append(User.Identity.GetUserId()).Append("/")
                                                 .Append(galleryId).ToString());

                var httpPostedFiles = HttpContext.Request.Files;

                var args = httpPostedFiles.AllKeys;
                for (int i = 0; i < args.Length; i++)
                {
                    var httpPostedFile = httpPostedFiles[i];
                    if (httpPostedFile != null)
                    {
                        // If the directory does not exist, create it
                        var path = new StringBuilder("~/Galleries/");
                        Directory.CreateDirectory(Server.MapPath(path.Append(User.Identity.GetUserId()).Append("/").Append(galleryId).ToString()));

                        // Validate the uploaded image(optional)

                        // Get the complete file path
                        var fileSavePath = Path.Combine(dir, Path.GetRandomFileName() + ".jpg");

                        // Save the uploaded file to "UploadedFiles" folder
                        httpPostedFile.SaveAs(fileSavePath);
                        gallery.PhotosList.Add(new PhotoModel(fileSavePath));
                    }
                }
                db.SaveChanges();
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }