Пример #1
0
        public PartialViewResult PriorityResult(AdminTicketViewModel model)
        {
            DatabaseContext db     = new DatabaseContext();
            int             result = -1;

            Models.Ticket ticket    = db.Tickets.Find(model.Ticket.Id);
            Models.Ticket oldticket = new Models.Ticket(ticket)
            {
                IsDeleted = true
            };
            db.Tickets.Add(oldticket);
            string user = Session["Login"].ToString();

            Log l = new Log
            {
                ObjecType      = typeof(Models.Ticket).ToString(),
                Type           = "Modified",
                Users          = db.Users.Where(x => x.Username == user && x.IsDeleted == false).FirstOrDefault(),
                PreviousTicket = oldticket,
                NexTicket      = ticket,
                IP             = HttpContext.Request.UserHostAddress,
                Time           = DateTime.Now,
                routevalues    = HttpContext.Request.Url.PathAndQuery
            };

            List <String> list = new List <String>();

            if (ticket != null && !ticket.IsDeleted)
            {
                if (ticket.Priority != model.Ticket.Priority)
                {
                    ticket.Priority = model.Ticket.Priority;
                    ticket.EditedOn = DateTime.Now;
                    l.Ticket        = ticket;
                    db.Logs.Add(l);
                    result = db.SaveChanges();
                }
            }
            if (result != 0)
            {
                list.Add("success");
                list.Add("Değişiklikler uygulanmıştır");
            }
            else
            {
                list.Add("danger");
                list.Add("Değişikler uygulanamamıştır");
            }

            return(PartialView("_Success", list));
        }
Пример #2
0
        public ActionResult Ticket(int id)
        {
            AdminTicketViewModel model = new AdminTicketViewModel();
            DatabaseContext      db    = new DatabaseContext();

            model.Admins = new List <Users>();
            foreach (Users u in db.Users.Where(x => !x.IsDeleted))
            {
                if (u.IsAdmin)
                {
                    model.Admins.Add(u);
                }
            }

            model.Ticket = db.Tickets.Find(id);

            if (model.Ticket.assignedTo != null)
            {
                model.TimeSpan = model.Ticket.assignedTo.Deadline.TimeOfDay;
            }
            model.AdminList = new List <SelectListItem>();
            foreach (Users u in model.Admins)
            {
                model.AdminList.Add(new SelectListItem()
                {
                    Text  = u.Username,
                    Value = u.ID.ToString(),
                });
            }

            if (model.Ticket.IsDeleted)
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #3
0
        public JsonResult DeleteTicket([DataSourceRequest] DataSourceRequest request, AdminTicketViewModel ticket)
        {
            if (ticket != null && ModelState.IsValid)
            {
                var filmEntity = this.Data.Films.GetById(ticket.FilmId);
                filmEntity.AvailableTickets++;
                this.Data.Films.Update(filmEntity);

                this.Data.Tickets.Delete(ticket.Id);
                this.Data.SaveChanges();
            }

            return(Json(new[] { ticket }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult Assign(AdminTicketViewModel p)
        {
            List <String> list = new List <String>();

            if (p.Ticket.assignedTo.Admin.ID != 0)
            {
                DatabaseContext db = new DatabaseContext();
                Models.Ticket   t  = db.Tickets.Find(p.Ticket.Id);
                if (t.IsDeleted)
                {
                    list.Add("danger");
                    list.Add("Bu bilet silinmiş.");
                    return(PartialView("_Success", list));
                }
                Users      u          = db.Users.Find(p.Ticket.assignedTo.Admin.ID);
                Assignment assignment = null;

                List <Assignment> alList = db.Assignments.Where(x => !x.IsDeleted).ToList();
                foreach (Assignment a in alList)
                {
                    if (a.Ticket == t)
                    {
                        assignment = a;

                        if (DateTime.Compare(p.Ticket.assignedTo.Deadline.Date.Add(p.TimeSpan), DateTime.Now) > 0)
                        {
                            Models.Ticket oldt = new Models.Ticket(t);

                            Assignment old = new Assignment
                            {
                                IsDeleted = true,
                                Admin     = a.Admin,
                                Ticket    = oldt,
                                Deadline  = a.Deadline,
                                IsDone    = a.IsDone
                            };
                            oldt.EditedOn       = DateTime.Now;
                            oldt.IsDeleted      = true;
                            assignment.Deadline = p.Ticket.assignedTo.Deadline.Date.Add(p.TimeSpan);
                            assignment.Admin    = u;
                            Log l = new Log
                            {
                                ObjecType  = typeof(Assignment).ToString(),
                                Assignment = assignment,
                                Type       = "Modified"
                            };
                            string user = Session["Login"].ToString();
                            l.Users = db.Users.Where(x => x.Username == user && x.IsDeleted == false).FirstOrDefault();
                            l.PreviousAssignment = old;
                            l.NextAssignment     = assignment;
                            l.IP          = HttpContext.Request.UserHostAddress;
                            l.Time        = DateTime.Now;
                            l.routevalues = HttpContext.Request.Url.PathAndQuery;

                            db.Tickets.Add(oldt);
                            db.Logs.Add(l);
                            db.Assignments.Add(old);
                        }
                        else
                        {
                            list.Add("danger");
                            list.Add("Lütfen geçerli bir tarih giriniz");
                            return(PartialView("_Success", list));
                        }
                    }
                }

                if (u != null && assignment == null)
                {
                    assignment = new Assignment {
                        Ticket = t, IsDone = false, Admin = u
                    };
                    if (DateTime.Compare(p.Ticket.assignedTo.Deadline.Date.Add(p.TimeSpan), DateTime.Now) > 0)
                    {
                        assignment.Deadline = p.Ticket.assignedTo.Deadline.Date.Add(p.TimeSpan);
                    }
                    else
                    {
                        list.Add("danger");
                        list.Add("Geçerli bir tarih giriniz");
                        return(PartialView("_Success", list));
                    }

                    db.Assignments.Add(assignment);
                }
                int result = db.SaveChanges();

                if (result != 0)
                {
                    list.Add("success");
                    list.Add("Değişiklikler uygulanmıştır");

                    //IJobDetail job = JobBuilder.Create<EmailClass>()  //send email every 6 hours
                    //    .WithIdentity("myJob", "group1")
                    //    .UsingJobData("Email", assignment.Admin.Email)
                    //    .UsingJobData("Time", assignment.Deadline.Subtract(DateTime.Now).Hours.ToString())
                    //    .UsingJobData("Body", assignment.Ticket.Text)
                    //    .UsingJobData("Seconds",assignment.Deadline.Subtract(DateTime.Now).Seconds.ToString())
                    //    .UsingJobData("Title",assignment.Ticket.Title).Build();
                    //ISimpleTrigger trigger = (ISimpleTrigger) TriggerBuilder.Create()
                    //    .WithIdentity("trigger1", "group1")
                    //    .StartAt(assignment.Deadline.AddDays(-1))
                    //    .WithSimpleSchedule(x=>x.WithIntervalInSeconds(2))
                    //    .ForJob("myJob", "group1")
                    //    .EndAt(assignment.Deadline)
                    //    .Build();
                    //StdSchedulerFactory factory = new StdSchedulerFactory();
                    //IScheduler scheduler = await factory.GetScheduler();
                    //await scheduler.Start();
                    //await scheduler.ScheduleJob(job, trigger);
                    //ISimpleTrigger trigger2 = (ISimpleTrigger) TriggerBuilder.Create()
                    //    .WithIdentity("trigger2", "group1")
                    //    .StartAt(assignment.Deadline.AddSeconds(-10))
                    //    .WithSimpleSchedule(x => x.WithIntervalInSeconds(1).WithRepeatCount(0))
                    //    .ForJob("myJob", "group1")
                    //    .Build();
                    //StdSchedulerFactory factory2 = new StdSchedulerFactory();

                    //IScheduler scheduler2 = await factory2.GetScheduler();
                    //await scheduler2.Start();
                    //await scheduler2.ScheduleJob(job, trigger2);
                    Email    email    = new Email();
                    DateTime deadline = assignment.Deadline;
                    deadline = DateTime.SpecifyKind(deadline, DateTimeKind.Local);
                    DateTimeOffset deadline2       = deadline;
                    long           unixTimeSeconds = deadline2.ToUnixTimeSeconds();

                    email.run_cmd(Server.MapPath("~/SendMail/sendmail.py"), assignment.Ticket.Author.Email.ToString() + " " + assignment.Ticket.Text + " " + assignment.Ticket.Title + " " + unixTimeSeconds);
                }
                else
                {
                    list.Add("danger");
                    list.Add("Değişikler uygulanamamıştır ya da değişiklik olmamıştır");
                }
            }
            else
            {
                list.Add("danger");
                list.Add("Lütfen geçerli bir kişi seçiniz");
            }

            return(PartialView("_Success", list));
        }