示例#1
0
        private void ProcessQueueMessage(CloudQueueMessage msg)
        {
            Trace.TraceInformation("Processing queue message {0}", msg);

            var   photoId = int.Parse(msg.AsString);
            Photo photo   = db.Photos.Find(photoId);

            if (photo == null)
            {
                throw new Exception(String.Format("PhotoId {0} not found, can't create thumbnail", photoId.ToString()));
            }

            Uri    blobUri  = new Uri(photo.ImageURL);
            string blobName = blobUri.Segments[blobUri.Segments.Length - 1];

            CloudBlockBlob inputBlob     = this.imagesBlobContainer.GetBlockBlobReference(blobName);
            string         thumbnailName = Path.GetFileNameWithoutExtension(inputBlob.Name) + "thumb.jpg";
            CloudBlockBlob outputBlob    = imagesBlobContainer.GetBlockBlobReference(thumbnailName);

            using (Stream input = inputBlob.OpenRead())
                using (Stream output = outputBlob.OpenWrite())
                {
                    ConvertImageToThumbnailJPG(input, output);
                    outputBlob.Properties.ContentType = "image/jpeg";
                }
            Trace.TraceInformation("Generated thumbnail in blob {0}", thumbnailName);

            photo.ThumbnailURL = outputBlob.Uri.ToString();
            db.SaveChanges();
            Trace.TraceInformation("Updated thumbnail URL in database: {0}", photo.ThumbnailURL);

            this.imagesQueue.DeleteMessage(msg);
        }
示例#2
0
 public void Insert(Income model)
 {
     using (var context = new PhotoGalleryContext())
     {
         context.Income.Add(model);
         context.SaveChanges();
     }
 }
示例#3
0
 public void Insert(Photographer model)
 {
     using (var context = new PhotoGalleryContext())
     {
         context.Photographer.Add(model);
         context.SaveChanges();
     }
 }
示例#4
0
 public void Insert(Stock model)
 {
     using (var context = new PhotoGalleryContext())
     {
         context.Stock.Add(model);
         context.SaveChanges();
     }
 }
示例#5
0
 public void Delete(int id)
 {
     using (var context = new PhotoGalleryContext())
     {
         Income element = context.Income.FirstOrDefault(rec => rec.Id == id);
         if (element != null)
         {
             context.Income.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Income not found");
         }
     }
 }
示例#6
0
 public void Update(Genre model)
 {
     using (var context = new PhotoGalleryContext())
     {
         var element = context.Genre.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             element.Name = model.Name;
             context.SaveChanges();
         }
         else
         {
             Insert(model);
         }
     }
 }
示例#7
0
 public void Update(Stock model)
 {
     using (var context = new PhotoGalleryContext())
     {
         var element = context.Stock.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             element.Address = model.Address;
             context.SaveChanges();
         }
         else
         {
             Insert(model);
         }
     }
 }
示例#8
0
 public void Update(Photographer model)
 {
     using (var context = new PhotoGalleryContext())
     {
         var element = context.Photographer.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             element.Name   = model.Name;
             element.Age    = model.Age;
             element.Status = model.Status;
             context.SaveChanges();
         }
         else
         {
             Insert(model);
         }
     }
 }
示例#9
0
 public void Update(Photo model)
 {
     using (var context = new PhotoGalleryContext())
     {
         var element = context.Photo.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             element.Photographerid = model.Photographerid;
             element.Photodate      = model.Photodate;
             element.Quality        = model.Quality;
             element.Rating         = model.Rating;
             element.Price          = model.Price;
             element.Genreid        = model.Genreid;
             context.SaveChanges();
         }
         else
         {
             Insert(model);
         }
     }
 }
 private bool ConfirmAccount(String confirmationToken)
 {
     using (var context = new PhotoGalleryContext())
     {
         var user = context.Users.SingleOrDefault(u => u.ConfirmationToken == confirmationToken);
         if (user != null)
         {
             user.IsConfirmed = true;
             var dbSet = context.Set<User>();
             dbSet.Attach(user);
             context.Entry(user).State = EntityState.Modified;
             context.SaveChanges();
             return true;
         }
     }
     return false;
 }
示例#11
0
 public virtual void Commit()
 {
     _context.SaveChanges();
 }
示例#12
0
 /// <summary>
 /// Create ClientProfile
 /// </summary>
 /// <param name="item">ClientProfile item</param>
 public void Create(ClientProfile item)
 {
     _database.ClientProfiles.Add(item);
     _database.SaveChanges();
 }
示例#13
0
 public IActionResult Create([FromBody] Comment comment)
 {
     dbContext.Comments.Add(comment);
     dbContext.SaveChanges();
     return(CreatedAtAction(nameof(Create), comment));
 }
示例#14
0
 public IActionResult Create([FromBody] Exhibit exhibit)
 {
     dbContext.Exhibits.Add(exhibit);
     dbContext.SaveChanges();
     return(CreatedAtAction(nameof(Create), exhibit));
 }