public static Response AutoGenerateClientName(string clientId)
 {
     using (ClientDataContext db = new ClientDataContext())
     {
         var client = db.Clients.FirstOrDefault(c => c.Id == clientId);
         var rnd    = new Random();
         client.Name = nicknames[rnd.Next(0, nicknames.Count - 1)];
         var clientState = db.ClientStates
                           .FirstOrDefault(c => c.ClientId == clientId);
         clientState.ClientStatus = Status.Default;
         db.SaveChanges();
         return(new Response($"Понимаю, вам неловко говорить своё имя...но все же я буду вас называть {client.Name}!)"));
     }
 }
 public static Response ContinueWorkOrChangeToDefaultState(string clientId, bool flag)
 {
     using (ClientDataContext db = new ClientDataContext())
     {
         var clientState = GetClientState(clientId);
         var response    = StateHelper.GetInstruction(clientState);
         if (!flag)
         {
             clientState.ClientStatus = Status.Default;
             response = new Response(@"Хорошо, как говорится, забудем ""старое""");
         }
         clientState.WaitingToContinue = false;
         db.ClientStates.Update(clientState);
         db.SaveChanges();
         return(response);
     }
 }
        public static Response AddStop(string clientId, string direction)
        {
            var clientState  = GetClientState(clientId);
            var directionUrl = (direction == "1" || direction == "первое")
                ? clientState.BufferDirections.First().Value
                : clientState.BufferDirections.Last().Value;
            var stopLink = Parser.GetStop(directionUrl, clientState.BufferStopName);

            if (stopLink == null)
            {
                return(ReturnDefaultState(clientId, "Я не смогла найти остановку с таким названием по указанному вами маршруту."));
            }
            var  stopUri = new Uri(stopLink);
            var  stopId  = HttpUtility.ParseQueryString(stopUri.Query).Get("st_id");
            Stop stop;

            using (ClientDataContext db = new ClientDataContext())
            {
                stop = db.Stops.Where(s => s.Id == stopId).FirstOrDefault();
                if (stop == null)
                {
                    stop = new Stop(stopId, clientState.BufferStopName, stopLink);
                    db.Stops.Add(stop);
                }
                if (GetClientTag(clientId, clientState.BufferTagName) != null)
                {
                    return(ReturnDefaultState(clientId, $"У вас уже есть такая остановка с тэгом {clientState.BufferTagName}"));
                }

                var clientTag = new ClientTag(clientId, clientState.BufferTagName, stopId);
                clientTag.Routes.Add(clientState.BufferRouteName);
                db.ClientTags.Add(clientTag);
                ReturnDefaultState(clientId, null);
                db.SaveChanges();
            }
            var timeIntervals = Parser.GetTime(stop, new List <string> {
                clientState.BufferRouteName
            });
            string result = $"Я добавила эту остановку по тегу {clientState.BufferTagName}. " +
                            "А вот и заодно время прибытия транспорта:\n";

            result += $"{string.Join("\n", timeIntervals[clientState.BufferRouteName])}";
            return(new Response($"{result}\n"));
        }
 public static Response GetResponseUserState(string clientId, string newSessionId)
 {
     using (ClientDataContext db = new ClientDataContext())
     {
         var clientState = GetClientState(clientId);
         clientState.SessionId = newSessionId;
         if (clientState.ClientStatus != Status.Default)
         {
             clientState.WaitingToContinue = true;
         }
         else
         {
             clientState.ClientStatus = Status.AnnouncingTag;
         }
         db.ClientStates.Update(clientState);
         db.SaveChanges();
         return(StateHelper.GetStateInfo(clientState));
     }
 }
        //public static bool UpdateDesign(DesignDummyViewModel dummy,int page_id)
        //{
        //    if (dummy.ad_id != 0)
        //    {
        //        var PageEntity = Unity.Work.Repository<tbl_dummy_page>().GetById(page_id);
        //        var PagePlacementEntity = Unity.Work.Repository<tbl_dummy_page_placement>().GetAll().Where(x => x.dummy_page_id == page_id).FirstOrDefault();
        //        var PagePlacementEntity = dummy.ToEntity(PagePlacementEntity.dummy_page_placement_id);
        //        PagePlacementEntity.tbl_dummy_page = PageEntity;
        //        Unity.Work.Repository<tbl_dummy_page_placement>().Update(PagePlacementEntity);

        //        Unity.Work.Save();
        //    }
        //    return true; ;
        //}
        public static List <tbl_dummy_page> CreatePages(int count, int start_page_number, int folio_id, string page_desc)
        {
            using (ClientDataContext context = new ClientDataContext())
            {
                var FolioEntity = context.tbl_dummy_folio.Where(x => x.dummy_folio_id == folio_id);
                var pages       = new List <tbl_dummy_page>();
                if (FolioEntity != null)
                {
                    for (var page = 0; page < count; page++)
                    {
                        pages.Add(CreateDummyPage(folio_id, new DummyPageViewModel {
                            page_name = page_desc, page_number = (page + start_page_number)
                        }));
                        context.tbl_dummy_page.AddRange(pages);
                    }
                    context.SaveChanges();
                }
                return(pages);
            }
        }
        public static Response FindRouteDirections(string clientId, string routeName)
        {
            var route = Parser.FindRouteNum(routeName);

            if (route == null)
            {
                return(new Response("Мне не удалось найти такой маршрут, проверьте правильность введенного номера маршрута"));
            }
            var directions = Parser.GetRouteChoice(route);

            using (ClientDataContext db = new ClientDataContext())
            {
                var clientState = GetClientState(clientId);
                clientState.ClientStatus     = Status.ChoosingDirection;
                clientState.BufferRouteName  = routeName;
                clientState.BufferDirections = directions;
                db.ClientStates.Update(clientState);
                db.SaveChanges();
                return(StateHelper.GetInstruction(clientState));
            }
        }
 public static DummyPageViewModel CreatePageByFolio(int folio_id)
 {
     using (ClientDataContext context = new ClientDataContext())
     {
         var maxPageCount = context.tbl_dummy_page.Where(x => x.dummy_folio_id == folio_id).Max(x => x.page_number).GetValueOrDefault();
         var pageModel    = new DummyPageViewModel {
             page_name = "page", page_number = (maxPageCount + 1)
         };
         var page = CreateDummyPage(folio_id, pageModel);
         context.tbl_dummy_page.Add(page);
         context.SaveChanges();
         return(new DummyPageViewModel
         {
             dummy_page_id = page.dummy_page_id,
             page_number = page.page_number.GetValueOrDefault(),
             page_name = page.page_name,
             page_note = page.page_note,
             page_status = page.page_status,
             is_deleted = page.is_deleted.GetValueOrDefault()
         });
     }
 }
        public static bool DeleteDummyFolio(int folio_id)
        {
            using (ClientDataContext context = new ClientDataContext())
            {
                var folioObj = context.tbl_dummy_folio.Where(x => x.dummy_folio_id == folio_id).FirstOrDefault();
                var pages    = context.tbl_dummy_page.Where(x => x.dummy_folio_id == folio_id);
                foreach (var page in pages)
                {
                    var placements = context.tbl_dummy_page_placement.Where(x => x.dummy_page_id == page.dummy_page_id);
                    context.tbl_dummy_page_placement.RemoveRange(placements);
                }
                context.tbl_dummy_page.RemoveRange(pages);
                context.tbl_dummy_folio.Remove(folioObj);
                var bottommFolios = context.tbl_dummy_folio.Where(x => x.iss_id == folioObj.iss_id && x.page_sequence > folioObj.page_sequence);
                foreach (var fo in bottommFolios)
                {
                    fo.page_sequence--;
                }

                context.SaveChanges();
            }
            return(true);
        }