Esempio n. 1
0
        [HttpPost]                          //Получаем заполненный объект заявки
        public ActionResult AddIssue(Issue issue)
        {
            using (IssuesSystemDBEntities IssuesDB = new IssuesSystemDBEntities())
            {
                //Создаём новую заявку в базе
                issue.State       = 1;
                issue.DateCreated = DateTime.Now;
                IssuesDB.Issues.Add(issue);
                IssuesDB.SaveChanges();

                //Создаём запись об изменении статуса заявки
                using (SqlCommand comm = new SqlCommand(string.Empty, new SqlConnection(IssuesDB.Database.Connection.ConnectionString)))
                {
                    comm.CommandText = ($"insert into IssueStateChanges (IdIssue,State,DateChanged) values ({issue.Id},{issue.State},@date_operation)");
                    comm.Parameters.Add(
                        "@date_operation", SqlDbType.DateTime, 80).Value = issue.DateCreated;
                    comm.Connection.Open();
                    comm.ExecuteNonQuery();
                }
            }



            return(Json(new { success = true, message = "Saved Issue Successfully" }, JsonRequestBehavior.AllowGet));
            //return View();
        }
Esempio n. 2
0
        public ActionResult CollectIssuesList()
        {
            //Перечень статусов заявок
            Dictionary <int, string> States =
                new Dictionary <int, string>
            {
                { 1, "Открыта" },
                { 2, "Решена" },
                { 3, "Возврат" },
                { 4, "Закрыта" }
            };

            using (IssuesSystemDBEntities issuesDB = new IssuesSystemDBEntities())
            {
                List <Issue> issuesList = issuesDB.Issues.ToList <Issue>();
                //Формируем особый, уличный, перечень заявок для отображения в таблице, взяв за основу перечень из базы
                List <IssueListToSend> issueListToSends = new List <IssueListToSend>();
                foreach (var issue in issuesList)
                {
                    string s = "";
                    if (issue.State != null)
                    {
                        States.TryGetValue((int)issue.State, out s);
                    }



                    issueListToSends.Add(
                        new IssueListToSend()
                    {
                        Id          = issue.Id,
                        State       = s,
                        Description = issue.Description,
                        DateCreated = issue.DateCreated.ToString()
                    }
                        );
                }
                return(Json(new { data = issueListToSends }, JsonRequestBehavior.AllowGet));
            }
        }