コード例 #1
0
        public ActionResult Delete(FormCollection values, int Id)
        {
            CheckAda();
            ApplicationUser user = GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            Image imageEntity = ApplicationDBContext.Images.Find(Id);

            if (imageEntity != null)
            {
                if (imageEntity.UserId == user.Id)
                {
                    //db.Entry(imageEntity).State = EntityState.Deleted;
                    ApplicationDBContext.Images.Remove(imageEntity);
                    ApplicationDBContext.SaveChanges();
                    ImageStorage.DeleteFile(Server, Id);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            else
            {
                return(RedirectToAction("Error", "Home", new { errid = "DeleteNotFound" }));
            }
        }
コード例 #2
0
        public ActionResult Delete(FormCollection vals, int Id)
        {
            CheckAda();
            ApplicationUser userid      = GetLoggedInUser();
            Image           imageEntity = db.Images.Find(Id);

            if (imageEntity != null)
            {
                //Validate the person is the owner of the image
                if (imageEntity.Userid.Equals(userid.Id))
                {
                    //db.Entry(imageEntity).State = EntityState.Deleted;
                    db.Images.Remove(imageEntity);
                    db.SaveChanges();
                    // Delete image from the file system
                    //System.IO.File.Delete(getFilePath(imageEntity.Id));

                    ImageStorage.DeleteFile(Server, imageEntity.Id);
                    QueueManager qm = new QueueManager(imageEntity.User.Id);
                    qm.addMessage(imageEntity, "Removed by User.");

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Error", "Home", new { errid = "DeleteNotAuth" }));
                }
            }
            else
            {
                return(RedirectToAction("Error", "Home", new { errid = "DeleteNotFound" }));
            }
        }
コード例 #3
0
        public void OnMessageReceived(BrokeredMessage receivedMessage)
        {
            try
            {
                Trace.WriteLine("Processing Service Bus message: " + receivedMessage.SequenceNumber.ToString());

                ValidationRequest request = receivedMessage.GetBody <ValidationRequest>();

                Image image = db.Images.Find(request.imageId);

                if (ImageStorage.Validate(request.imageId))
                {
                    image.Validated = true;
                    db.SaveChanges();
                }
                else
                {
                    ImageStorage.DeleteFile(null, request.imageId);
                    db.Images.Remove(image);
                    db.SaveChanges();
                }

                receivedMessage.Complete();
            }
            catch
            {
                // Handle any Message
            }
        }
コード例 #4
0
        public ActionResult Delete(List <SelectItemView> model)
        {
            CheckAda();
            var db = new ApplicationDbContext();

            foreach (var umod in model)
            {
                ApplicationUser user = db.Users.Find(umod.Id);
                umod.Name = user.UserName;
                if (user.Active && umod.Checked)
                {
                    foreach (Image image in user.Images.ToArray())
                    {
                        db.Images.Remove(image);
                        //Remove the blobs
                        ImageStorage.DeleteFile(Server, image.Id);
                    }
                    user.Active = false;
                }
                else if (!user.Active && !umod.Checked)
                {
                    user.Active = true;
                }
            }

            db.SaveChanges();
            ViewBag.Message = "User successfully deactivated/reactivated.";

            return(View(model));
        }