Пример #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);
        }
Пример #2
0
 public override void Create(Picture item)
 {
     if (item == null)
     {
         throw new Exception("Picture is empty");
     }
     context.Pictures.Add(item);
     context.SaveChanges();
 }
Пример #3
0
 public void Commit()
 {
     context.SaveChanges();
 }