Inheritance: ExtensibleDataObject
Ejemplo n.º 1
0
        public async Task UploadPhoto(int userId, PhotoCreateDto model)
        {
            //var file = model.File;
            Microsoft.AspNetCore.Http.IFormFile file = model.File;
            var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/assets/images/", userId.ToString(), file.FileName);

            using (var db = base.NewDb())
            {
                using (var stream = System.IO.File.Create(path))
                {
                    await file.CopyToAsync(stream);
                }

                bool isMain = true;
                if (await HasMainPhoto(userId))
                {
                    isMain = false;
                }

                var memberPhoto = new MemberPhoto()
                {
                    UserId       = userId,
                    AddedDate    = System.DateTime.Now,
                    Descriptions = model.descriptions ?? file.FileName,
                    IsMain       = isMain,
                    PhotoUrl     = path
                };

                db.Add(memberPhoto);
                await db.SaveChangesAsync();

                return;
            }
        }
Ejemplo n.º 2
0
        public MemberViewModel(Member member, MemberPhoto photo, string eventId, string eName, string gId, string gName, long eDate)
        {
            this.Member    = member;
            this.eventId   = eventId;
            this.eventName = eName;
            this.groupId   = gId;
            this.groupName = gName;
            this.eventDate = eDate;
            this.Photo     = photo ?? new MemberPhoto
            {
                HighResLink = DefaultIcon,
                PhotoId     = 0,
                ThumbLink   = DefaultIcon,
                PhotoLink   = DefaultIcon
            };

            if (string.IsNullOrWhiteSpace(this.Photo.HighResLink))
            {
                this.Photo.HighResLink = DefaultIcon;
            }


            if (string.IsNullOrWhiteSpace(this.Photo.ThumbLink))
            {
                this.Photo.ThumbLink = DefaultIcon;
            }

            if (string.IsNullOrWhiteSpace(this.Photo.PhotoLink))
            {
                this.Photo.PhotoLink = DefaultIcon;
            }
        }
        public MemberPhoto CreateMemberPhotoObject(MemberPhoto photo)
        {
            var image = new MemberPhoto
            {
                MemberId  = photo.MemberId,
                AppUserId = photo.AppUserId,
                Photo     = photo.Photo,
                Thumbnail = photo.Thumbnail,
                MimeType  = photo.MimeType
            };

            return(image);
        }
        private void UpdateExistingPhoto(MemberPhoto existingPhoto, MemberPhoto photo)
        {
            // delete existing photo in container
            // store new file name in table
            // upload new photo to blob



            //existingPhoto.Photo = photo.Photo;
            //existingPhoto.Thumbnail = photo.Thumbnail;
            //existingPhoto.MimeType = photo.MimeType;
            //db.ImageRepository.Update(existingPhoto);
        }
        //public void PersistImage(byte[] file, int memberId, string mimeType)
        //{
        //    // Save image to database.
        //    if (file == null) return;
        //    var image = CreateMemberPhotoObject(file, memberId, mimeType);

        //    db.ImageRepository.Add(image);
        //}

        public MemberPhoto CreateMemberPhotoObject(byte[] file, int memberId, string mimeType)
        {
            var member = db.MemberRepository.FindMemberById(memberId);

            var image = new MemberPhoto
            {
                Member    = member,
                Photo     = file,
                Thumbnail = file,
                MimeType  = mimeType
            };

            return(image);
        }
Ejemplo n.º 6
0
        public MemberViewModel(Page page, Member member, MemberPhoto photo, string eventId, string eName, string gId, string gName, long eDate, int guests = 0) : base(page)
        {
            this.guests = string.Empty;

            if (guests == 1)
            {
                this.guests = "1 guest";
            }
            else if (guests > 1)
            {
                this.guests = guests + " guests";
            }

            Member       = member;
            this.eventId = eventId;
            eventName    = eName;
            groupId      = gId;
            groupName    = gName;
            eventDate    = eDate;
            Photo        = photo ?? new MemberPhoto
            {
                HighResLink = DefaultIcon,
                PhotoId     = 0,
                ThumbLink   = DefaultIcon,
                PhotoLink   = DefaultIcon
            };

            if (string.IsNullOrWhiteSpace(Photo.HighResLink))
            {
                Photo.HighResLink = DefaultIcon;
            }


            if (string.IsNullOrWhiteSpace(Photo.ThumbLink))
            {
                Photo.ThumbLink = DefaultIcon;
            }

            if (string.IsNullOrWhiteSpace(Photo.PhotoLink))
            {
                Photo.PhotoLink = DefaultIcon;
            }
        }