Beispiel #1
0
        public Models.File LoadByArtworkId(int id)
        {
            if (id != null)
            {
                List <Models.File> files   = new List <Models.File>();
                BL.Artwork         artwork = new BL.Artwork();

                var file = db.Files.FirstOrDefault(f => f.ArtworkId == id);
                if (file != null)
                {
                    Models.File f = new Models.File
                    {
                        Id          = file.Id,
                        ArtworkId   = file.ArtworkId,
                        UserId      = file.UserId,
                        Content     = file.Content,
                        ContentType = file.ContentType,
                        FileName    = file.FileName,
                        Artwork     = artwork.LoadById(file.ArtworkId)
                    };
                    return(f);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
 public List <Models.File> LoadByUserId(int id)
 {
     if (id != null)
     {
         List <Models.File> files    = new List <Models.File>();
         BL.Artwork         artwork  = new BL.Artwork();
         Models.FileType    fileType = new Models.FileType();
         db.Files.Where(f => f.UserId == id)
         .ToList()
         .ForEach(f => files
                  .Add(new Models.File
         {
             Id          = f.Id,
             ArtworkId   = f.ArtworkId,
             UserId      = f.UserId,
             FileName    = f.FileName,
             FileType    = (Models.FileType)f.FileType,
             ContentType = f.ContentType,
             Content     = f.Content,
             Artwork     = artwork.LoadById(f.ArtworkId)
         }));
         return(files);
     }
     else
     {
         return(null);
     }
 }
Beispiel #3
0
        public bool Delete(int id)
        {
            BL.Artwork         artwork  = new BL.Artwork();
            Net.Models.Artwork _artwork = new Net.Models.Artwork();
            Net.Models.Message _message = new Net.Models.Message();

            _artwork = artwork.LoadById(id);

            var existArt  = db.Artworks.SingleOrDefault(x => x.Id == id);
            var existFile = db.Files.SingleOrDefault(f => f.ArtworkId == id);
            var existCol  = db.Collections.SingleOrDefault(f => f.Id == _artwork.CollectionMessageId);
            var existMsg  = db.Messages.Where(a => a.CollectionId == _artwork.CollectionMessageId).ToList();

            if (existArt != null || existFile != null || existCol != null)
            {
                db.Artworks.Remove(existArt);
                db.Files.Remove(existFile);
                db.Collections.Remove(existCol);
                existMsg.ForEach(x => db.Messages.Remove(x));
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        public List <Models.File> Load()
        {
            List <Models.File> files = new List <Models.File>();

            BL.Artwork artwork = new BL.Artwork();
            db.Files.ToList().ForEach(f => files
                                      .Add(new Models.File
            {
                Id          = f.Id,
                FileName    = f.FileName,
                ContentType = f.ContentType,
                Content     = f.Content,
                UserId      = f.UserId,
                ArtworkId   = f.ArtworkId,
                Artwork     = artwork.LoadById(f.ArtworkId)
            }));

            return(files);
        }
Beispiel #5
0
        public List <Models.File> LoadByUserGalleryId(int userId, int galleryId)
        {
            if (userId != null && galleryId != null)
            {
                List <Models.File> files   = new List <Models.File>();
                BL.Artwork         artwork = new BL.Artwork();

                var results = (from f in db.Files
                               join a in db.Artworks on f.ArtworkId equals a.Id
                               where (a.GalleryId == galleryId && f.UserId == userId)
                               select new
                {
                    f.Id,
                    f.ArtworkId,
                    f.UserId,
                    f.FileName,
                    f.ContentType,
                    f.Content,
                    f.FileType
                }).ToList();

                foreach (var r in results)
                {
                    files.Add(new Models.File
                    {
                        Id          = r.Id,
                        ArtworkId   = r.ArtworkId,
                        UserId      = r.UserId,
                        FileName    = r.FileName,
                        ContentType = r.ContentType,
                        Content     = r.Content,
                        FileType    = (Models.FileType)r.FileType,
                        Artwork     = artwork.LoadById(r.ArtworkId)
                    });;
                }
                return(files);
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        public List <Models.File> LoadByUserFileTypeId(int userId, Net.Models.FileType fileType)
        {
            if (fileType != null)
            {
                List <Models.File> files   = new List <Models.File>();
                BL.Artwork         artwork = new BL.Artwork();

                var results = (from f in db.Files
                               where (f.FileType == (tblFileType)fileType && f.UserId == userId)
                               select new
                {
                    f.Id,
                    f.ArtworkId,
                    f.UserId,
                    f.FileName,
                    f.ContentType,
                    f.Content,
                    f.FileType
                }).ToList();

                foreach (var r in results)
                {
                    files.Add(new Models.File
                    {
                        Id          = r.Id,
                        ArtworkId   = r.ArtworkId,
                        UserId      = r.UserId,
                        FileName    = r.FileName,
                        ContentType = r.ContentType,
                        Content     = r.Content,
                        FileType    = (Models.FileType)r.FileType,
                        Artwork     = artwork.LoadById(r.ArtworkId)
                    });
                }
                return(files);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
        public ActionResult Edit(UserGalleryArtworkFile ugaf, Net.Models.File file, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                //ugaf.User = (Net.Models.User)Session["user"];
                Net.Models.User user = (Net.Models.User)Session["user"];
                BL.User userHelper = new BL.User();
                BL.File fileHelper = new BL.File();
                BL.Artwork artworkHelper = new BL.Artwork();

                var oldFile = fileHelper.LoadByUserId(user.Id);
                Net.Models.File existingFile = new Net.Models.File();


                Net.Models.User newUser = userHelper.LoadById(user.Id);

                using (userHelper = new BL.User())
                {
                    newUser.FirstName = ugaf.User.FirstName;
                    newUser.LastName = ugaf.User.LastName;
                    newUser.Password = ugaf.User.Password;
                    newUser.CommissionActive = ugaf.User.CommissionActive;
                }

                foreach (var f in oldFile)
                {
                    existingFile.ArtworkId = f.ArtworkId;
                    existingFile.Content = f.Content;
                    existingFile.ContentType = f.ContentType;
                    existingFile.FileName = f.FileName;
                    existingFile.FileType = f.FileType;
                    existingFile.Id = f.Id;
                    existingFile.UserId = f.UserId;
                    existingFile.Artwork = artworkHelper.LoadById(f.ArtworkId);
                    existingFile.User = newUser;
                }

                try
                {
                    if (upload != null && upload.ContentLength > 0)
                    {
                        file = new Net.Models.File
                        {
                            Id = existingFile.Id,
                            FileName = System.IO.Path.GetFileName(upload.FileName),
                            FileType = FileType.Avatar,
                            ContentType = upload.ContentType,
                            Content = existingFile.Content,
                            Artwork = existingFile.Artwork,
                            User = existingFile.User,
                            UserId = existingFile.UserId,
                            ArtworkId = existingFile.ArtworkId
                        };
                        using (var reader = new System.IO.BinaryReader(upload.InputStream))
                        {
                            file.Content = reader.ReadBytes(upload.ContentLength);
                        }

                        System.Diagnostics.Debug.WriteLine(newUser.Id);
                        System.Diagnostics.Debug.WriteLine(file.FileName);
                        ugaf.User.Files = new List<Net.Models.File> { file };
                        userHelper.Update(newUser, file);
                    }
                    else
                    {
                        ugaf.User = newUser;
                        userHelper.Update(newUser, existingFile);
                    }

                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                    return View(ugaf);
                }
            }
            return View();
        }