/// <summary>
        /// Update Photo async
        /// </summary>
        /// <param name="entity">Photo entity</param>
        /// <returns></returns>
        public async Task UpdateAsync(Photo entity)
        {
            var photoEntity = await _context.Photos.FindAsync(entity.Id);

            _context.Photos.Attach(photoEntity);
            _context.Entry(photoEntity).State = System.Data.Entity.EntityState.Modified;
        }
        public async Task <ActionResult> Edit([Bind(Include = "PhotoId, Title, Description, ImageURL, ThumbnailURL, PostedDate")] Photo photo, HttpPostedFileBase imageFile)
        {
            CloudBlockBlob imageBlob = null;

            if (ModelState.IsValid)
            {
                if (imageFile != null && imageFile.ContentLength != 0)
                {
                    await DeleteAdBlobsAsync(photo);

                    imageBlob = await UploadAndSaveBlobAsync(imageFile);

                    photo.ImageURL = imageBlob.Uri.ToString();
                }

                db.Entry(photo).State = EntityState.Modified;
                await db.SaveChangesAsync();

                Trace.TraceInformation("Updated PhotoId {0} in database", photo.PhotoId);

                if (imageBlob != null)
                {
                    var queueMessage = new CloudQueueMessage(photo.PhotoId.ToString());
                    await imagesQueue.AddMessageAsync(queueMessage);

                    Trace.TraceInformation("Created queue message for PhotoId {0}", photo.PhotoId);
                }
                return(RedirectToAction("Index"));
            }
            return(View(photo));
        }
示例#3
0
        public IActionResult Update([FromBody] Comment comment)
        {
            Comment commentToModify = dbContext.Comments.Find(comment.Id);

            commentToModify.Title   = comment.Title;
            commentToModify.Content = comment.Content;
            //change date or bool would be nice
            dbContext.Entry(commentToModify).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            dbContext.SaveChanges();
            return(Ok(comment));
        }
 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;
 }
示例#5
0
        public virtual void Add(T entity)
        {
            EntityEntry dbEntityEntry = _context.Entry <T>(entity);

            _context.Set <T>().Add(entity);
        }