public Photo(PhotoDataModel photoData) { PhotoId = photoData.PhotoId; PhotoName = photoData.PhotoName; UploadDate = photoData.UploadDate; PhotoUrl = photoData.PhotoUrl; Albums = new List <Album>(); Comments = new List <Comment>(); }
public void PhotoDataMapTest() { var model = new PhotoDataModel { MimeType = Guid.NewGuid().ToString(), Data = Guid.NewGuid().ToByteArray() }; var entity = Mapper.Map <PhotoData>(model); Assert.Equal(model.MimeType, entity.MimeType); Assert.Equal(model.Data, entity.Data); }
public Photo(PhotoDataModel dataModel) { Comments = new List <Comment>(); Albums = new List <Album>(); PhotoID = dataModel.PhotoID; Name = dataModel.Name; Url = dataModel.Url; uploader = dataModel.uploader; UploadedDate = dataModel.UploadedDate; // Comments = dataModel.Comments.Select(x => new Comment(x)).ToList(); // Albums = dataModel.Albums.Select(x => new Album(x)).ToList(); }
public PhotoDataModel Transform() { var dataModel = new PhotoDataModel { PhotoId = this.PhotoId, PhotoName = this.PhotoName, UploadDate = this.UploadDate, PhotoUrl = this.PhotoUrl, Albums = this.Albums.Select(a => a.Transform()).ToList(), Comments = this.Comments.Select(c => c.Transform()).ToList() }; return(dataModel); }
public bool AddOrUpdate(PhotoDataModel photo) { try { using (var ctx = new MVCContext()) { var photoToUpdate = ctx.Photos.Where(p => p.ID == photo.ID) .Include(p => p.User) .Include(p => p.Comments) .Include(p => p.Album) .FirstOrDefault(); if (photoToUpdate != null) { photoToUpdate.Name = photo.Name; photoToUpdate.AlbumID = photo.AlbumID; photoToUpdate.Path = photo.Path; photoToUpdate.publik = photo.publik; photoToUpdate.Description = photo.Description; photoToUpdate.Datecreated = photo.Dateupdated; ctx.SaveChanges(); return(true); } else { var newPhoto = new PhotoDataModel(); newPhoto.User = photo.User; newPhoto.Album = photo.Album; newPhoto.Name = photo.Name; newPhoto.AlbumID = photo.AlbumID; newPhoto.Path = photo.Path; newPhoto.publik = photo.publik; newPhoto.Description = photo.Description; newPhoto.Datecreated = photo.Datecreated; newPhoto.Dateupdated = photo.Dateupdated; newPhoto.UserID = photo.UserID; ctx.Photos.Add(newPhoto); ctx.SaveChanges(); return(true); } } } catch (Exception e) { //Handle exceptions } return(false); }
public PhotoDataModel Transform() { var photodata = new PhotoDataModel { PhotoID = this.PhotoID, Name = this.Name, Url = this.Url, uploader = this.uploader, UploadedDate = this.UploadedDate, Comments = this.Comments.Select(x => x.Transform()).ToList(), Albums = this.Albums.Select(x => x.Transform()).ToList() }; return(photodata); }
public void Add(PhotoDataModel Photo) { using (var ctx = new TheContext()) { var existingPhoto = ctx.Photos.FirstOrDefault(x => x.PhotoID == Photo.PhotoID); if (existingPhoto == null) { ctx.Photos.Add(Photo); ctx.SaveChanges(); } else { existingPhoto.Update(Photo); ctx.Entry(existingPhoto).State = EntityState.Modified; ctx.SaveChanges(); } } }
public static PhotoDataModel ModelToEntity(PhotoVM model) { PhotoDataModel entity = new PhotoDataModel(); entity.Name = model.Name; entity.ID = model.id; entity.Path = model.Path; entity.UserID = model.UserID; entity.Description = model.Description; entity.Datecreated = model.DatePosted; entity.Dateupdated = model.DateEdited; entity.AlbumID = model.AlbumID; entity.publik = model.IsPublicPhoto; return(entity); }
public static PhotoVM EntityToModel(PhotoDataModel entity) { PhotoVM model = new PhotoVM(); model.Name = entity.Name; model.id = entity.ID; model.Path = entity.Path; model.UserID = entity.UserID; model.Description = entity.Description; model.DatePosted = entity.Datecreated; model.DateEdited = entity.Dateupdated; model.AlbumID = entity.AlbumID; model.IsPublicPhoto = entity.publik; entity.User = repouser.ByID((int)entity.UserID); model.User = EntityToModel(entity.User); model.Uploader = entity.User.FirstName + " " + entity.User.LastName; return(model); }