Ejemplo n.º 1
0
        public List <Models.Message> Load()
        {
            BL.User user = new BL.User();
            List <Models.Message> messages = new List <Models.Message>();

            db.Messages
            .ToList()
            .ForEach(m => messages
                     .Add(
                         new Models.Message
            {
                Id           = m.Id,
                FromUserId   = m.FromUserId,
                ToUserId     = m.ToUserId,
                Body         = m.Body,
                CollectionId = m.CollectionId,
                DateTime     = m.DateTime,
                CritiqueId   = m.CritiqueId,
                Rating       = m.Rating,
                X            = m.X,
                Y            = m.Y,
                FromUsername = (user.LoadById(m.FromUserId).UserName == null || user.LoadById(m.FromUserId).UserName == String.Empty) ? "User Not Found" : user.LoadById(m.FromUserId).UserName
            }));

            return(messages);
        }
Ejemplo n.º 2
0
        public List <Models.Message> LoadByCollection(int collectionId)
        {
            BL.User user = new BL.User();
            List <Models.Message> messages = new List <Models.Message>();

            db.Messages.Where(x => x.CollectionId == collectionId)
            .ToList()
            .ForEach(x => messages
                     .Add(new Models.Message
            {
                Id           = x.Id,
                FromUserId   = x.FromUserId,
                ToUserId     = x.ToUserId,
                Body         = x.Body,
                CollectionId = x.CollectionId,
                DateTime     = x.DateTime,
                CritiqueId   = x.CritiqueId,
                Rating       = x.Rating,
                X            = x.X,
                Y            = x.Y,
                FromUsername = (user.LoadById(x.FromUserId).UserName == null || user.LoadById(x.FromUserId).UserName == String.Empty) ? "User Not Found" : user.LoadById(x.FromUserId).UserName
            }));
            return(messages);
        }
Ejemplo n.º 3
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();
        }