Exemplo n.º 1
0
        public ActionResult ChangePassword(ViewModels.ChangePasswordViewModel model)
        {
            User user = db.Users.Find(model.UserId);

            if (CheckChangePassword(user, model.OldPassword, model.NewPassword))
            {
                db.SaveChanges();
            }

            return(View("Index", db.Users.ToList()));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Name,LogoUrl,Deleted")] Product product)
        {
            if (ModelState.IsValid)
            {
                product.Id = Guid.NewGuid();
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Type")] TicketType tickettype)
        {
            if (ModelState.IsValid)
            {
                tickettype.Id = Guid.NewGuid();
                db.TicketTypes.Add(tickettype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tickettype));
        }
Exemplo n.º 4
0
        public ActionResult ReadMailbox()
        {
            ViewData["TicketCount"] = 0;
            var user = db.Users.FirstOrDefault(u => u.Id.ToString() == User.Identity.Name);

            if (user == null)
            {
                return(PartialView("TicketIndicator"));
            }
            var company = user.Company;

            // user should get a company when they sign up to trex
            if (company == null)
            {
                return(PartialView("TicketIndicator"));
            }
            var emailIds = db.Tickets.Where(t => !string.IsNullOrEmpty(t.EmailId)).Select(te => te.EmailId).ToList();

            var newMail = FetchUnseenMessages(company.MailBoxServer,
                                              company.MailboxPort,
                                              company.MailboxSsl,
                                              company.MailBoxEmailAddress,
                                              company.MailBoxPassword,
                                              emailIds);

            foreach (var message in newMail)
            {
                var customer = db.Customers.FirstOrDefault(cust => cust.Email == message.Headers.From.Address) ??
                               new Customer {
                    Id = Guid.NewGuid(), Email = message.Headers.From.Address
                };
                var te = new Ticket
                {
                    Customer = customer,
                    Notes    = message.FindFirstPlainTextVersion().GetBodyAsText(),
                    Subject  = message.Headers.Subject,
                    Added    = DateTime.Now,
                    Due      = DateTime.Now.AddDays(DueDateDays),
                    Id       = Guid.NewGuid()
                };
                db.Tickets.Add(te);
            }
            db.SaveChanges();

            ViewData["TicketCount"] = newMail.Count;


            return(PartialView("TicketIndicator"));
        }
Exemplo n.º 5
0
        public void TestMethodPrimaryKeyConstraint()
        {
            var cx = new TrexContext();

            Guid sameGuid = Guid.NewGuid();

            for (int i = 0; i < 2; i++)
            {
                cx.Tickets.Add(new Ticket()
                {
                    Id           = sameGuid,
                    Added        = DateTime.Now,
                    AssigneeUser = null,
                    Due          = DateTime.Now.AddYears(1),
                });
            }

            try
            {
                cx.SaveChanges();
            }
            catch (DbUpdateException)
            {
                Assert.IsTrue(true, "All is well, primary key constraint is working");
            }
        }
Exemplo n.º 6
0
        public void TestMethodSaveTicket()
        {
            var cx = new TrexContext();

            var initial = cx.Tickets.Count();

            for (int i = 0; i < 5; i++)
            {
                cx.Tickets.Add(new Ticket()
                {
                    Id           = Guid.NewGuid(),
                    Added        = DateTime.Now,
                    AssigneeUser = null,
                    Due          = DateTime.Now.AddYears(1),
                    Notes        = "testingtestingthisbreakxyz12312DHV(UGIWHOIEHF(&*#@^$%^*&(@#",
                    Subject      = "test ticket count",
                    Submitter    = "bob jones"
                });
            }
            cx.SaveChanges();
            cx.Dispose();

            var cx2   = new TrexContext();
            var after = cx2.Tickets.Count();

            Assert.AreEqual(initial + 5, after, "Not 5 records saved");
        }
Exemplo n.º 7
0
        void CreateDefaultUser()
        {
            User u = new User()
            {
                Id             = Guid.NewGuid(),
                Email          = "*****@*****.**",
                HashedPassword = "******"
            };

            db.Users.Add(u);
            db.SaveChanges();
        }
Exemplo n.º 8
0
        public void TestSecurable()
        {
            var cx = new TrexContext();

            cx.Tickets.Add(new Ticket()
            {
                Id       = Guid.NewGuid(),
                Added    = DateTime.Now,
                IsSecure = true,
                Notes    = "{15F022A6-8289-4888-9498-20CC84C80833}"
            });
            cx.Tickets.Add(new Ticket()
            {
                Id       = Guid.NewGuid(),
                Added    = DateTime.Now,
                IsSecure = false,
                Notes    = "{15F022A6-8289-4888-9498-20CC84C80833}"
            });
            cx.SaveChanges();
            var sec     = new TrexSecureContext();
            var tickets = sec.Get <Ticket>().Count(u => u.Notes == "{15F022A6-8289-4888-9498-20CC84C80833}");

            Assert.IsTrue(tickets == 1);
        }