private string GetState(Wiki.OrdersTables order)
 {
     if (order.dateRemove != null)
     {
         return("Отменен");
     }
     else if (order.dateClose != null)
     {
         return("Поступил");
     }
     else
     {
         return("Ожидание");
     }
 }
        public JsonResult Add(int[] ordersList)
        {
            string login = HttpContext.User.Identity.Name;

            using (PortalKATEKEntities db = new PortalKATEKEntities())
            {
                db.Configuration.ProxyCreationEnabled = false;
                db.Configuration.LazyLoadingEnabled   = false;
                Wiki.OrdersTables order = new Wiki.OrdersTables
                {
                    dateCreate           = DateTime.Now,
                    dateClose            = null,
                    dateRemove           = null,
                    isActive             = true,
                    id_AspNetUsersCreate = db.AspNetUsers.First(a => a.Email == login).Id
                };
                db.OrdersTables.Add(order);
                db.SaveChanges();
                foreach (var data in ordersList)
                {
                    OrdersTablesPositions pos = new OrdersTablesPositions();
                    pos.id_PZ_PlanZakaz = data;
                    pos.id_OrdersTables = order.id;
                    pos.isActive        = true;
                    db.OrdersTablesPositions.Add(pos);
                    db.SaveChanges();
                }
                string directory = @"\\192.168.1.30\m$\_ЗАКАЗЫ\Таблички\" + order.id.ToString() + "\\";
                Directory.CreateDirectory(directory);
                DirectoryInfo dr = new DirectoryInfo(@"\\192.168.1.30\m$\_ЗАКАЗЫ\Таблички\BU\");
                foreach (FileInfo fi in dr.GetFiles("*.cdr"))
                {
                    fi.CopyTo(directory + fi.Name, true);
                }
                string[] body = GetFileBodyCRD(ordersList, directory);
                System.IO.File.WriteAllLines(directory + "RecordedMacros.bas", body, Encoding.Unicode);
                body = GetArrayFileBodyCRD(ordersList);
                System.IO.File.WriteAllLines(directory + "RecordedMacros.txt", body, Encoding.Unicode);
                return(Json(1, JsonRequestBehavior.AllowGet));
            }
        }