public ActionResult RateIssue(IssueDetailsViewModel issueDetails)
        {
            Issue issue = db.Issues.Find(issueDetails.Id);

            if (issue == null)
            {
                return(HttpNotFound());
            }
            issue.Rate        = issueDetails.Rate;
            issue.RateComment = issueDetails.CommentRate;
            issue.State       = 2;
            issue.EndDate     = DateTime.Now;
            db.SaveChanges();
            var userMails = new List <string>();
            var userId    = User.Identity.GetUserId();

            userMails.Add(db.Users.First(u => u.Id == userId).Email);
            var type = db.Types.First(t => t.Id == issue.TypeId);

            foreach (var user in type.Users)
            {
                userMails.Add(user.Email);
            }
            SendMail.InformUsers(userMails, issue, User.Identity.Name, "", 4);
            TempData["Success"] = "Usterka została oceniona i przeniesiona do archiwum!";
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult AddComment(IssueDetailsViewModel issueDetails)
        {
            Issue issue = db.Issues.Find(issueDetails.Id);

            if (issue == null)
            {
                return(HttpNotFound());
            }
            var comm = new Comment();

            comm.UserId  = User.Identity.GetUserId();
            comm.Content = issueDetails.CommentContent;
            comm.Date    = DateTime.Now;
            issue.Comments.Add(comm);
            db.SaveChanges();
            var userMails = new List <string>();
            var userId    = User.Identity.GetUserId();

            userMails.Add(db.Users.First(u => u.Id == userId).Email);
            var type = db.Types.First(t => t.Id == issue.TypeId);

            foreach (var user in type.Users)
            {
                userMails.Add(user.Email);
            }
            SendMail.InformUsers(userMails, issue, User.Identity.Name, comm.Content, 2);
            TempData["Success"] = "Dodano nowy komentarz!";
            return(RedirectToAction("Details", "Issue", new { id = issueDetails.Id }));
        }
        public ActionResult Create(IssuesViewModel issueVM, HttpPostedFileBase upload)
        {
            var issue = new Issue()
            {
                UserId          = User.Identity.GetUserId(),
                StartDate       = DateTime.Now,
                EndDate         = DateTime.Now,
                InventoryNumber = issueVM.InventoryNumber,
                State           = 0,
                Rate            = 1,
                Description     = issueVM.Description,
                Title           = issueVM.Title,
                TypeId          = issueVM.TypeId
            };

            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var attachment = new ReportAnIssue.Models.File
                    {
                        FileName    = System.IO.Path.GetFileName(upload.FileName),
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        attachment.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    db.Files.Add(attachment);
                    db.SaveChanges();
                    issue.FileId = attachment.Id;
                }
                db.Issues.Add(issue);
                db.SaveChanges();
            }
            var userMails = new List <string>();
            var userId    = User.Identity.GetUserId();

            userMails.Add(db.Users.First(u => u.Id == userId).Email);
            var type = db.Types.First(t => t.Id == issue.TypeId);

            foreach (var user in type.Users)
            {
                userMails.Add(user.Email);
            }
            SendMail.InformUsers(userMails, issue, User.Identity.Name, "", 1);
            TempData["Success"] = "Dodano nową usterkę!";
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult IssueDone(IssueDetailsViewModel issueDetails)
        {
            Issue issue = db.Issues.Find(issueDetails.Id);

            if (issue == null)
            {
                return(HttpNotFound());
            }
            issue.State = 1;
            db.SaveChanges();
            var userMails = new List <string>();
            var userId    = User.Identity.GetUserId();

            userMails.Add(db.Users.First(u => u.Id == userId).Email);
            var type = db.Types.First(t => t.Id == issue.TypeId);

            SendMail.InformUsers(userMails, issue, "", "", 3);
            TempData["Success"] = "Usterka została wykonana. Użytkownik został poinformowany!";
            return(RedirectToAction("Index", "Home"));
        }