示例#1
0
        public ActionResult Attachment([Bind(Include = "TicketId,Description,Created,UserId,FileUrl")] int id, TicketAttachments ticketAttachments, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    ticketAttachments.FileUrl = "/Uploads/" + fileName;
                }
                ticketAttachments.Created  = DateTime.Now;
                ticketAttachments.UserId   = User.Identity.GetUserId();
                ticketAttachments.TicketId = id;
                db.TicketAttachments.Add(ticketAttachments);
                db.SaveChanges();

                var Tickets = db.Tickets.Where(x => x.Id == ticketAttachments.TicketId).FirstOrDefault();
                if (Tickets.AssigneeId != null)
                {
                    var personalEmailService = new PersonalEmailService();
                    var mailMessage          = new MailMessage(WebConfigurationManager.AppSettings["emailto"], Tickets.Assignee.Email);
                    mailMessage.Body       = "added attachment";
                    mailMessage.IsBodyHtml = true;
                    personalEmailService.Send(mailMessage);
                }


                return(RedirectToAction("Index", "Tickets"));
            }


            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "Name", ticketAttachments.UserId);
            return(View(ticketAttachments));
        }
        public ActionResult CreateAttachment(int id, string UserId, [Bind(Include = "Description,FilePath")] TicketAttachment ticketAttachment, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    if (ImageUploadValidator.IsWebFriendlyImage(image))
                    {
                        var fileName = Path.GetFileName(image.FileName);
                        image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                        ticketAttachment.FilePath = "/Uploads/" + fileName;
                    }

                    ticketAttachment.TicketId = id;
                    ticketAttachment.UserId   = User.Identity.GetUserId();
                    ticketAttachment.Created  = DateTime.Now;
                    db.Attachments.Add(ticketAttachment);
                    db.SaveChanges();

                    var ticket = db.Tickets.Where(p => p.Id == ticketAttachment.TicketId).FirstOrDefault();
                    if (ticket.AssigneeId != null)
                    {
                        var personalEmailService = new PersonalEmailService();
                        var mailMessage          = new MailMessage(WebConfigurationManager.AppSettings["emailto"], ticket.Assignee.Email);
                        mailMessage.IsBodyHtml = true;
                        personalEmailService.Send(mailMessage);
                    }

                    return(RedirectToAction("Details", new { id = id }));
                }
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            return(View(ticketAttachment));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "Id,Created,Updated,Title,Body,MediaUrl,Published,Slug")] CliffBlogPost cliffBlogPosts, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var Slug = StringUtilities.URLFriendly(cliffBlogPosts.Title);
                if (String.IsNullOrWhiteSpace(Slug))
                {
                    ModelState.AddModelError("Title", "Invalid title");
                    return(View(cliffBlogPosts));
                }
                if (db.Posts.Any(p => p.Slug == Slug))
                {
                    ModelState.AddModelError("Title", "The title must be unique");
                    return(View(cliffBlogPosts));
                }


                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);                    //clicked light bulb for using System.IO;
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); //clicked light bulb for using System.IO;
                    cliffBlogPosts.MediaURL = "/Uploads/" + fileName;                   //change URL to Url??
                }


                cliffBlogPosts.Slug    = Slug;
                cliffBlogPosts.Created = DateTime.Now;
                db.Posts.Add(cliffBlogPosts);
                //db.Posts.Add(image);  // do I need this line?  I added, seems like I do but get squiggles under image
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cliffBlogPosts));
        }
        public ActionResult AddAttachment(HttpPostedFileBase image, int ticketId)
        {
            TicketAttachment ta = new TicketAttachment();

            if (ImageUploadValidator.IsWebFriendlyImage(image))
            {
                var fileName = Path.GetFileName(image.FileName);
                image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                ta.FileUrl = "/Uploads/" + fileName;
            }

            ta.TicketId = ticketId;
            ta.Created  = DateTimeOffset.Now;
            db.TicketAttachments.Add(ta);
            db.SaveChanges();

            TicketHistory history = new TicketHistory()
            {
                Changed  = DateTime.Now,
                TicketId = ticketId,
                Property = "Added Attachment",
                UserId   = User.Identity.GetUserId()
            };

            db.TicketHistories.Add(history);
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = ta.TicketId }));
        }
示例#5
0
        public ActionResult Edit([Bind(Include = "Id,Created,Updated,Title,Slug,Body,MediaURL,Published,Abstract")] BlogPost blogPost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var Slug = StringUtilities.URLFriendly(blogPost.Title);
                if (String.IsNullOrWhiteSpace(Slug))
                {
                    ModelState.AddModelError("Title", "Invalid title");
                    return(View(blogPost));
                }
                if (Slug != blogPost.Slug && db.BlogPosts.Any(p => p.Slug == Slug))
                {
                    ModelState.AddModelError("Title", "The title must be unique");
                    return(View(blogPost));
                }

                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.MediaURL = "/Uploads/" + fileName;
                }

                db.Entry(blogPost).State = EntityState.Modified;
                blogPost.Slug            = Slug;
                blogPost.Updated         = DateTimeOffset.Now;
                db.SaveChanges();
                return(RedirectToAction("Details", "BlogPosts", new { Slug = Slug }));
            }
            return(View(blogPost));
        }
        public ActionResult Create([Bind(Include = "Id,Description,Name,ProjectId,Created,Updated,PriorityId,StatusId,TypeId,CreatorId,AssignedId")] TicketModels ticketModels, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();
                ticketModels.CreatorId = userId;
                ticketModels.Created   = DateTimeOffset.Now;
                ticketModels.StatusId  = 1;

                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));

                    var iomg = new TicketAttachment();
                    iomg.FilePath = "/Uploads/" + fileName;
                }

                db.TicketModels.Add(ticketModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AssigneeId = new SelectList(db.Users, "Id", "Name", ticketModels.AssignedId);
            ViewBag.CreatorId  = new SelectList(db.Users, "Id", "Name", ticketModels.CreatorId);
            ViewBag.PriorityId = new SelectList(db.Priority, "Id", "Name", ticketModels.PriorityId);
            ViewBag.StatusId   = new SelectList(db.Status, "Id", "Name", ticketModels.StatusId);
            ViewBag.TypeId     = new SelectList(db.Type, "Id", "Name", ticketModels.TypeId);
            ViewBag.ProjectId  = new SelectList(db.Projects, "Id", "Name", ticketModels.ProjectId);

            return(View(ticketModels));
        }
        public ActionResult MyProfile(MyProfileModel model, HttpPostedFileBase avatar)
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            user.FullName  = $"{model.FirstName} {model.LastName}";
            user.Email     = model.Email;

            if (avatar != null)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(avatar))
                {
                    var fileName     = Path.GetFileName(avatar.FileName);
                    var justFileName = Path.GetFileNameWithoutExtension(fileName);
                    justFileName = StringUtilities.URLFriendly(justFileName);
                    fileName     = $"{justFileName} {DateTime.Now.Ticks}{Path.GetExtension(fileName)}";
                    avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatar/"), fileName));
                    user.AvatarUrl = "/Avatar/" + fileName;
                }
            }

            db.SaveChanges();


            return(RedirectToAction("MyProfile"));
        }
示例#8
0
        public ActionResult Create([Bind(Include = "Post, Topics")] BlogTopicsViewModel model, HttpPostedFileBase Image, string button)
        {
            if (ModelState.IsValid)
            {
                var Slug = StringUtilities.URLFriendly(model.Post.Title);
                if (String.IsNullOrWhiteSpace(Slug))
                {
                    ModelState.AddModelError("Title", "Invalid title");
                    return(View(model));
                }
                if (db.Posts.Any(p => p.Slug == Slug))
                {
                    ModelState.AddModelError("Title", "The title must be unique");
                    return(View(model));
                }
                var ErrorMessage = "";
                if (ImageUploadValidator.IsWebFriendlyImage(Image))
                {
                    var fileName   = Path.GetFileName(Image.FileName);
                    var customName = string.Format(Guid.NewGuid() + fileName);
                    Image.SaveAs(Path.Combine(Server.MapPath("~/NEWIMAGES/"), customName));
                    model.Post.MediaURL = "~/NEWIMAGES/" + customName;
                }
                else
                {
                    ViewBag.ErrorMessage = "Please select an image between 1KB-2MB and in an approved format (.jpg, .bmp, .png, .gif)";



                    model.Post.MediaURL = "images/module-1.jpg";
                }
                model.Post.createdDate = DateTime.Now;

                model.Post.Slug = Slug;
                if (button == "Create")
                {
                    model.Post.Published = false;
                }
                else
                {
                    model.Post.Published = true;
                }

                db.Posts.Add(model.Post);
                db.SaveChanges();

                if (model.Topics != null)
                {
                    foreach (var vm in model.Topics)
                    {
                        int topicId = Convert.ToInt32(vm);
                        helper.AddTopicToBlog(topicId, model.Post.Id);
                    }
                }

                return(RedirectToAction("Index", new { message = ErrorMessage }));
            }
            ViewBag.Topics = new MultiSelectList(db.Topics, "Id", "Description");
            return(View(model));
        }
        public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment ticketAttachment, string attachmentTitle, string attachmentDescription, HttpPostedFileBase attachment)
        {
            if (attachment == null)
            {
                return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId }));
            }

            if (ModelState.IsValid)
            {
                ticketAttachment.Title       = attachmentTitle;
                ticketAttachment.Description = attachmentDescription;
                ticketAttachment.Created     = DateTime.Now;
                ticketAttachment.UserId      = User.Identity.GetUserId();

                if (ImageUploadValidator.IsValidAttachment(attachment))
                {
                    var fileName = Path.GetFileName(attachment.FileName);
                    attachment.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    ticketAttachment.FileUrl = "/Uploads/" + fileName;
                }


                db.TicketAttachments.Add(ticketAttachment);
                db.SaveChanges();
                return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId }));
            }


            return(View(ticketAttachment));
        }
        public ActionResult Edit([Bind(Include = "Id,Created,Title,Slug,Body,MediaPath,Abstract,Published")] BlogPost blogPost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var slug = StringUtilities.URLFriendly(blogPost.Title);

                //Ask the question as to whether or not the slug is blank
                if (String.IsNullOrWhiteSpace(slug))
                {
                    ModelState.AddModelError("Title", "Invalid Title, try again!");
                    return(View(blogPost));
                }

                //Determines whether or not the slug has already been recorded
                if (db.BlogPosts.Any(b => b.Slug == slug))
                {
                    ModelState.AddModelError("Title", "This Title appears to have been used before and must be unique");
                    return(View(blogPost));
                }

                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = System.IO.Path.GetFileName(image.FileName);
                    image.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.MediaPath = "/Uploads/" + fileName;
                }

                blogPost.Slug            = slug;
                blogPost.Updated         = DateTime.Now;
                db.Entry(blogPost).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(blogPost));
        }
        public ActionResult EditProfile(UserViewModel user, HttpPostedFileBase Avatar)
        {
            if (ModelState.IsValid)
            {
                var newUser = db.Users.Find(user.Id);
                {
                    newUser.FirstName   = user.FirstName;
                    newUser.LastName    = user.LastName;
                    newUser.DisplayName = user.DisplayName;
                    newUser.Email       = user.Email;
                    newUser.ProfilePic  = user.ProfilePic;
                    newUser.UserName    = user.Email;
                }

                if (Avatar != null)
                {
                    if (ImageUploadValidator.IsWebFriendlyImage(Avatar))
                    {
                        var fileName = Path.GetFileName(Avatar.FileName);
                        Avatar.SaveAs(Path.Combine(Server.MapPath("~/ProfilePictures/"), fileName));
                        newUser.ProfilePic = "/ProfilePictures/" + fileName;
                    }
                }

                db.SaveChanges();
            }
            return(RedirectToAction("ProfilePage", "Home"));
        }
示例#12
0
        public async Task <ActionResult> Index(ApplicationUser model, HttpPostedFileBase image)
        {
            var userId = User.Identity.GetUserId();

            model = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userId);

            if (ImageUploadValidator.IsWebpageFriendlyImage(image))
            {
                TempData["avatarCheck"] = "Success";
                var fileName = Path.GetFileName(image.FileName);
                image.SaveAs(Path.Combine(Server.MapPath("~/Avatar/"), fileName));
                model.avatar = "/Avatar/" + fileName;
            }
            else
            {
                TempData["avatarCheck"] = "Failure";
            }

            db.Users.Attach(model);
            db.Entry(model).State = EntityState.Modified;
            db.SaveChanges();

            var viewModel = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                currentUser       = UserManager.FindById(userId),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            return(View(viewModel));
        }
示例#13
0
        public ActionResult Edit([Bind(Include = "Id,Title,Body,MediaUrl,Published")] BlogPost blogPost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var blog = db.BlogPosts.Where(p => p.Id == blogPost.Id).FirstOrDefault();
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blog.MediaUrl = "/Uploads/" + fileName;
                }

                if (blog.Title != blogPost.Title)
                {
                    if ((db.BlogPosts.Any(p => p.Title == blogPost.Title && p.Id != blogPost.Id)))
                    {
                        blogPost.Slug = StringUtilities.URLFriendly(blogPost.Title) + "-" + Guid.NewGuid();
                        blog.Slug     = blogPost.Slug;
                    }
                    else
                    {
                        blog.Slug = StringUtilities.URLFriendly(blog.Title);
                    }
                }
                blog.Title     = blogPost.Title;
                blog.Body      = blogPost.Body;
                blog.Published = blogPost.Published;
                blog.Updated   = DateTime.Now;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(blogPost));
        }
        public ActionResult Create([Bind(Include = "TicketId")] TicketAttachment ticketAttachment, string attachmentTitle, string attachmentDescription, HttpPostedFileBase FilePath)
        {
            if (ModelState.IsValid)
            {
                ticketAttachment.Title       = attachmentTitle;
                ticketAttachment.Description = attachmentDescription;
                ticketAttachment.Created     = DateTime.Now;
                ticketAttachment.UserId      = User.Identity.GetUserId();
                //using my imageHelpers to decide if it is good file or not

                if (ImageUploadValidator.IsValidAttachment(FilePath))
                {
                    var fileName = Path.GetFileName(FilePath.FileName);
                    FilePath.SaveAs(Path.Combine(Server.MapPath("~/Attachments/"), fileName));
                    ticketAttachment.FilePath = "/Attachments/" + fileName;
                }
                db.TicketAttachments.Add(ticketAttachment);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(RedirectToAction("Dashboard", "Tickets", new { id = ticketAttachment.TicketId }));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
        public async Task <ActionResult> CreateTicketAttachments([Bind(Include = "Id,TicketId,UserId,FilePath,Description,Created,FileUrl")] TicketAttachments ticketAttachments, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                Tickets tickets = db.Tickets.FirstOrDefault();

                ApplicationUser NotifyUser = db.Users.FirstOrDefault(u => u.Id.Equals(tickets.AssignedToUserId));

                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/assets/Uploads/"), fileName));
                    ticketAttachments.FileUrl = "~/assets/Uploads/" + fileName;
                }
                ticketAttachments.UserId  = User.Identity.GetUserId();
                ticketAttachments.Created = DateTimeOffset.Now;
                db.TicketAttachments.Add(ticketAttachments);
                db.SaveChanges();

                if (NotifyUser != null /*|| !(await UserManager.IsEmailConfirmedAsync(user.Id))*/)
                {
                    var callBackUrl = Url.Action("Details", "Tickets", new { id = ticketAttachments.Ticket.Id }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(NotifyUser.Id, "Ticket Update" + ticketAttachments.Ticket.Id, "Good day, this is a notification of changes to this  <a href=\"" + callBackUrl + "\">ticket</a> you area assigned.");
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId);
            return(View(ticketAttachments));
        }
示例#16
0
        public ActionResult Create([Bind(Include = "Title,Abstract,Body,Published")] BlogPost blogPost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)

            {
                var Slug = StringUtilities.URLFriendly(blogPost.Title);
                if (String.IsNullOrWhiteSpace(Slug))
                {
                    ModelState.AddModelError("Title", "Invalid title");
                    return(View(blogPost));
                }
                if (db.BlogPosts.Any(p => p.Slug == Slug))
                {
                    ModelState.AddModelError("Title", "the Title must be unique");
                    return(View(blogPost));
                }
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.MediaURL = "/Uploads/" + fileName;
                }



                blogPost.Slug    = Slug;
                blogPost.Created = DateTime.Now;
                db.BlogPosts.Add(blogPost);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(blogPost));
        }//you can tell what the difference between a post and a get is by HTTP POST (id,item or whatever you want to call it in the brackets)
示例#17
0
        public ActionResult Create([Bind(Include = "Id,Title,Body,MediaURL,Published")] BlogPost blogPost, HttpPostedFileBase image)
        {
            //This if statement ensures all data required above ^^^ is entered & valid
            if (ModelState.IsValid)
            {
                var Slug = StringUtilities.URLFriendly(blogPost.Title);
                if (String.IsNullOrWhiteSpace(Slug))
                {
                    ModelState.AddModelError("Title", "Invalid title");
                    return(View(blogPost));
                }
                if (db.Posts.Any(p => p.Slug == Slug))
                {
                    ModelState.AddModelError("Title", "The title must be unique");
                    return(View(blogPost));
                }

                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.MediaURL = "/Uploads/" + fileName;
                }

                blogPost.Slug    = Slug;                //This assigns each blog post a slug (plain english URL)
                blogPost.Created = DateTimeOffset.Now;  //This grabs the systems time & automatically sets the value for Created
                db.Posts.Add(blogPost);                 //Go to the db & find the Posts table & add it (the blogPost) to the table
                db.SaveChanges();                       //Self explanatory - saves changes to the db
                return(RedirectToAction("Index"));      //Once it saves return to the Index page listed to the Index Action above in Line 19
            }

            return(View(blogPost));
        }
        public async Task <ActionResult> AddAttachment([Bind(Include = "Id,TicketId,Description,MediaURL")] Attachment attachment, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (ImageUploadValidator.IsWebFriendly(image))
                {
                    if (ImageUploadValidator.IsImage(image) || image.FileName.Contains(".pdf") || image.FileName.Contains(".doc"))
                    {
                        var fileName = Path.GetFileName(image.FileName);
                        var uniqueId = DateTime.Now.Ticks;
                        fileName = Regex.Replace(fileName, @"[!@#$%_\s]", "");
                        image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), uniqueId + fileName));
                        attachment.MediaURL = "/Uploads/" + uniqueId + fileName;
                    }
                    else
                    {
                        return(View());
                    }
                }
                attachment.AuthorId = User.Identity.GetUserId();
                db.Attachments.Add(attachment);
                db.SaveChanges();

                var ticket = db.Tickets.Find(attachment.TicketId);
                await NotifyDeveloper(attachment.TicketId, attachment.AuthorId, ticket.AssigneeId);

                return(RedirectToAction("Details", new { id = attachment.TicketId }));
            }
            return(View());
        }
示例#19
0
        public ActionResult Create([Bind(Include = "Id,Created,Updated,Title,Slug,Body,MediaURL,Published")] BlogPost blogPost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var Slug = StringUtilities.URLFriendly(blogPost.Title);
                //var Snip = SnippetStripper.StripTagsCharArray(blogPost.Body);
                if (String.IsNullOrWhiteSpace(Slug))
                {
                    ModelState.AddModelError("Title", "Invalid title");
                    return(View(blogPost));
                }
                if (db.BlogPosts.Any(p => p.Slug == Slug))
                {
                    ModelState.AddModelError("Title", "Title must be unique");
                    return(View(blogPost));
                }

                if (ImageUploadValidator.IsWEebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.MediaURL = "/Uploads/" + fileName;
                }
                return(RedirectToAction("Index"));
            }
            return(View(blogPost));
        }
示例#20
0
        //[Authorize(Roles = "Admin")]

        public ActionResult Edit([Bind(Include = "Id,Title,Abstract,Slug,BlogPostBody,ImagePath,Published,Created")] BlogPost blogPost, HttpPostedFileBase picture)
        {
            if (ModelState.IsValid)
            {
                #region Picture Upload
                if (ImageUploadValidator.IsWebFriendlyImage(picture))
                {
                    var fileName = Path.GetFileName(picture.FileName);

                    fileName  = StringUtilities.URLFriendly(Path.GetFileNameWithoutExtension(fileName));
                    fileName += "_" + DateTime.Now.Ticks + Path.GetExtension(picture.FileName);

                    picture.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.ImagePath = "/Uploads/" + fileName;
                }
                #endregion


                blogPost.Updated         = DateTime.Now;
                db.Entry(blogPost).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "BlogPosts"));
            }
            return(View(blogPost));
        }
示例#21
0
        public ActionResult UploadAttachment([Bind(Include = "Id,TicketId,FilePath,FileUrl,Description,Created")] TicketAttachment ticketattachment, HttpPostedFileBase image)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var filename   = Path.GetFileName(image.FileName);
                    var customname = string.Format(Guid.NewGuid() + filename);
                    image.SaveAs(Path.Combine(Server.MapPath("~/upload/"), customname));
                    ticketattachment.FileUrl = customname;
                }
                else
                {
                    ViewBag.StatusMessage    = "Please select proper image";
                    ticketattachment.FileUrl = "defaultImg.jpg"; // default image
                    return(View(ticketattachment));
                }

                ticketattachment.FilePath = "~/upload/";
                ticketattachment.Created  = DateTime.Now;
                ticketattachment.UserId   = User.Identity.GetUserId();
                db.TicketAttachments.Add(ticketattachment);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit([Bind(Include = "Id,Created,Title,Slug,Abstract,Body,MediaURL,Published")] BlogPost blogPost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    //isolating file name
                    var justFileName = Path.GetFileNameWithoutExtension(image.FileName);
                    //running through slug checker
                    justFileName = StringUtilities.URLFriendly(justFileName);
                    //adding time stamp width ticks
                    justFileName = $"{justFileName}-{DateTime.Now.Ticks}";
                    //adding the extension back on
                    justFileName = $"{justFileName}{Path.GetExtension(image.FileName)}";

                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), justFileName));
                    blogPost.MediaURL = "/Uploads/" + justFileName;
                }


                blogPost.Updated         = DateTime.Now;
                db.Entry(blogPost).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(blogPost));
        }
        public ActionResult EditProfile(UserInformationViewModel model, HttpPostedFileBase avatar)
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            user.FirstName   = model.Fname;
            user.LastName    = model.Lname;
            user.DisplayName = model.DisplayName;
            user.Email       = model.Email;
            user.UserName    = model.Email;
            //db.Entry(editUser);

            if (avatar != null)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(avatar))
                {
                    var filename = Path.GetFileName(avatar.FileName);
                    avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), filename));
                    user.AvatarPath = "/Avatars/" + filename;
                }
            }

            db.SaveChanges();
            return(RedirectToAction("EditProfile", "Home"));
        }
        public ActionResult Edit([Bind(Include = "Id,Title,Created,Abstract,Slug,Body,MediaUrl,Published")] Blog blog, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var slug = StringUtilities.URLFriendly(blog.Title);
                if (blog.Slug != slug)
                {
                    if (string.IsNullOrEmpty(slug))
                    {
                        ModelState.AddModelError("Title", "Oops, looks like you forgot a title!");
                        return(View(blog));
                    }
                    if (db.Blogs.Any(b => b.Slug == slug))
                    {
                        ModelState.AddModelError("", $"Oops, the title '{blog.Title}' has been used before.");
                    }
                    blog.Slug = slug;

                    if (ImageUploadValidator.IsWebFriendlyImage(image))
                    {
                        var fileName = Path.GetFileName(image.FileName);
                        image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));

                        blog.MediaUrl = "/Uploads/" + fileName;
                    }
                }
                blog.Updated         = DateTime.Now;
                db.Entry(blog).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(blog));
        }
示例#25
0
        public async Task <ActionResult> Create([Bind(Include = "Id,TicketId,Body,Created,UserId,FilreUrl")] TicketAttachment ticketAttachment, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    ticketAttachment.FileUrl = "/Uploads/" + fileName;
                }
                ticketAttachment.Created = DateTime.Now;
                ticketAttachment.UserId  = User.Identity.GetUserId();
                db.TicketAttachments.Add(ticketAttachment);
                db.SaveChanges();
                var tkt       = db.Tickets.Find(ticketAttachment.TicketId);
                var developer = tkt.AssignedToUserId;
                await UserManager.SendEmailAsync(developer, "New Ticket Comment", "A new comment as appeared on your assigned ticket, " + tkt.Title + ".");

                return(RedirectToAction("Details", "Tickets", new { id = tkt.Id }));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
        public ActionResult Create(Category category, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var fileName = Path.GetFileName(image.FileName);

                    fileName = DateTime.Now.Ticks + fileName;
                    WebImage img = new WebImage(image.InputStream);
                    if (img.Width > 100)
                    {
                        img.Resize(100, img.Height);
                    }

                    if (img.Height > 190)
                    {
                        img.Resize(img.Width, 190);
                    }

                    img.Save(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    category.CatCoverPic = "/Uploads/" + fileName;
                }

                category.Created = DateTime.Now;
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
示例#27
0
        public ActionResult UserProfileEdit(UserProfile model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null && ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    var justFileName = System.IO.Path.GetFileNameWithoutExtension(image.FileName);
                    justFileName = StringUtilities.URLFriendly(justFileName);
                    justFileName = $"{justFileName}--{DateTime.Now.Ticks}";
                    justFileName = $"{justFileName}{System.IO.Path.GetExtension(image.FileName)}";

                    model.AvatarUrl = "/Avatars/" + justFileName;
                    image.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Avatars/"), justFileName));
                }


                var currentUser = db.Users.Find(User.Identity.GetUserId());
                currentUser.FirstName  = model.FirstName;
                currentUser.LastName   = model.LastName;
                currentUser.UserName   = model.Email;
                currentUser.Email      = model.Email;
                currentUser.AvatarPath = model.AvatarUrl;

                db.SaveChanges();
                return(RedirectToAction("Dashboard", "Home"));
            }

            return(View());
        }
        public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase avatar)
        {
            if (ModelState.IsValid)
            {
                var fileName = Path.GetFileName(avatar.FileName);
                if (ImageUploadValidator.IsWebFriendlyImage(avatar))
                {
                    avatar.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                }

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, Avatar = "/Uploads/" + fileName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "BlogPosts"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public ActionResult Create([Bind(Include = "Id,Title,Body,MediaURL,Published")] BlogPost blogPost, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         var Slug = StringUtilities.URLFriendly(blogPost.Title);
         if (String.IsNullOrWhiteSpace(Slug))
         {
             ModelState.AddModelError("Title", "Invalid title");
             return(View(blogPost));
         }
         if (db.Posts.Any(p => p.Slug == Slug))
         {
             ModelState.AddModelError("Title", "The title must be unique");
             return(View(blogPost));
         }
         if (ImageUploadValidator.IsWebFriendlyImage(image))
         {
             var fileName = Path.GetFileName(image.FileName);
             image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
             blogPost.MediaUrl = "/Uploads/" + fileName;
         }
         blogPost.Slug    = Slug;
         blogPost.Created = DateTimeOffset.Now;
         db.Posts.Add(blogPost);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(blogPost));
 }
示例#30
0
        public ActionResult Edit([Bind(Include = "Id, Title, Abstract, BlogPostBody,Published,Created,Slug, ImagePath")] BlogPost blogPost, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                var newSlug = StringUtilities.URLFriendly(blogPost.Title);
                if (newSlug != blogPost.Slug)
                {
                    if (string.IsNullOrWhiteSpace(newSlug))
                    {
                        ModelState.AddModelError("Title", "Invalid title");
                        return(View(blogPost));
                    }
                    if (db.BlogPosts.Any(p => p.Slug == newSlug))
                    {
                        ModelState.AddModelError("Title", "The title must be unique");
                        return(View(blogPost));
                    }
                    blogPost.Slug = newSlug;
                }
                if (ImageUploadValidator.IsWebFriendlyImage(Image))
                {
                    var fileName = Path.GetFileName(Image.FileName);
                    Image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    blogPost.ImagePath = "/Uploads/" + fileName;
                }

                blogPost.Updated         = DateTime.Now;
                db.Entry(blogPost).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(blogPost));
        }