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); }
public void Insert(Income model) { using (var context = new PhotoGalleryContext()) { context.Income.Add(model); context.SaveChanges(); } }
public void Insert(Photographer model) { using (var context = new PhotoGalleryContext()) { context.Photographer.Add(model); context.SaveChanges(); } }
public void Insert(Stock model) { using (var context = new PhotoGalleryContext()) { context.Stock.Add(model); context.SaveChanges(); } }
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"); } } }
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); } } }
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); } } }
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); } } }
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; }
public virtual void Commit() { _context.SaveChanges(); }
/// <summary> /// Create ClientProfile /// </summary> /// <param name="item">ClientProfile item</param> public void Create(ClientProfile item) { _database.ClientProfiles.Add(item); _database.SaveChanges(); }
public IActionResult Create([FromBody] Comment comment) { dbContext.Comments.Add(comment); dbContext.SaveChanges(); return(CreatedAtAction(nameof(Create), comment)); }
public IActionResult Create([FromBody] Exhibit exhibit) { dbContext.Exhibits.Add(exhibit); dbContext.SaveChanges(); return(CreatedAtAction(nameof(Create), exhibit)); }