public Guid UpdatePicture(Guid projectId, Stream pictureData) { if (!_context.Pictures.Any(p => p.Id == projectId)) { throw new KeyNotFoundException("Project not found"); } var entity = _context.Pictures.SingleOrDefault(c => c.ProjectId == projectId); bool newEntity = entity == null; if (newEntity) { entity = new Entities.Picture() { ProjectId = projectId } } ; entity.Data = ReadFully(pictureData); if (newEntity) { _context.Add(entity); } else { _context.Update(entity); } _context.SaveChanges(); return(projectId); }
private async Task SavePicture(Guid id, Picture picture) { if (picture != null) { Entities.Picture entity = new Entities.Picture { Id = id, Bytes = picture._bytes, Name = picture._name, Size = picture._size, Type = picture._type }; await _context.Pictures.ReplaceOneAsync(x => x.Id == id, entity, new ReplaceOptions { IsUpsert = true }); } }
internal static void LoadLogos(long userId, List <Entities.Picture> list) { /* * if (Model.Profile.Logos != null && Model.Profile.Logos.Count > 0) * { * } * else * { * uri = "/Content/Users/Common/Images/Logo.png"; * } * */ Entities.Picture picture = new Entities.Picture(); picture.Url = "/Content/Users/7/profile.jpg"; list.Add(picture); }
private async Task <Picture> GetPicture(Guid id) { Entities.Picture entity = await _context.Pictures.Find(x => x.Id == id).FirstOrDefaultAsync(); return(Picture.Load(entity.Bytes, entity.Size, entity.Type, entity.Name)); }
public void UpdatePicture(Entities.Picture picture) { // No implementation required because the EF core monitors the entity we extracted from the database // and when we change that object and do SaveChanges all changes will be persistent }
public void CreatePicture(Entities.Picture picture) { context.Pictures.Add(picture); }
public void Add(Entities.Picture picture) { _pictures.Add(picture); }
public void Update(Entities.Picture picture) { _pictures.Update(picture); }