Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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 });
     }
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
 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
 }
Esempio n. 6
0
 public void CreatePicture(Entities.Picture picture)
 {
     context.Pictures.Add(picture);
 }
Esempio n. 7
0
 public void Add(Entities.Picture picture)
 {
     _pictures.Add(picture);
 }
Esempio n. 8
0
 public void Update(Entities.Picture picture)
 {
     _pictures.Update(picture);
 }