//----------------------------------------------------------------// public async Task <String> CreateDailyCaseAsync(TimeSpan time, String name, Int64 chatId) { Case @case = new Case(name, time, chatId); using (ISession session = SessionFactory.CreateSession()) { ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); return(_caseExist(await caseCommand.SaveIfNotExist(caseQuery, @case))); } }
//----------------------------------------------------------------// public async Task <String> CreateConcretyDateCaseAsync(DateTime dateTime, TimeSpan timeSpan, String name, Int64 chatId) { ConcretyDateCase concretyDate = new ConcretyDateCase(name, timeSpan, chatId); Boolean isAdded = false; using (ISession session = SessionFactory.CreateSession()) { ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); IQuery <CaseDate, CaseDateId> caseDateQuery = QueryFactory.CreateQuery <IQuery <CaseDate, CaseDateId> >(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); ICommand <CaseDate, CaseDateId> caseDateCommand = CommandFactory.CreateCommand <ICommand <CaseDate, CaseDateId> >(session); isAdded = await caseCommand.SaveIfNotExist(caseQuery, concretyDate) && await caseDateCommand.SaveIfNotExist(caseDateQuery, new CaseDate(concretyDate, dateTime)); } return(_caseExist(isAdded)); }
//----------------------------------------------------------------// public async Task <String> CreateWeeklyCaseAsync(List <DayOfWeek> dayOfWeeks, TimeSpan time, String name, Int64 chatId) { WeeklyCase weeklyCase = new WeeklyCase(name, time, chatId, dayOfWeeks); Boolean isAdded = false; using (ISession session = SessionFactory.CreateSession()) { ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); IQuery <CaseDayOfWeek, CaseDayOfWeekId> caseDayOfWeekQuery = QueryFactory.CreateQuery <IQuery <CaseDayOfWeek, CaseDayOfWeekId> >(session); ICommand <CaseDayOfWeek, CaseDayOfWeekId> caseDayOfWeekCommand = CommandFactory.CreateCommand <ICommand <CaseDayOfWeek, CaseDayOfWeekId> >(session); isAdded = await caseCommand.SaveIfNotExist(caseQuery, weeklyCase); IEnumerable <CaseDayOfWeek> caseDayOfWeeks = dayOfWeeks.Select(c => new CaseDayOfWeek(weeklyCase, c)); await caseDayOfWeekCommand.SaveIfNotExistCollection(caseDayOfWeekQuery, caseDayOfWeeks); } return(_caseExist(isAdded)); }
//----------------------------------------------------------------// public async Task <ProcessResult> TryGenerateOrUpdateSequence(ISession session, String nameCase, String[] userNames) { String result = null; IEnumerable <UserCaseSequencer> sequencers = null; ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); Case @case = await caseQuery.GetCaseByNameAsync(nameCase); if (@case != null) { IUserQuery userQuery = QueryFactory.CreateQuery <IUserQuery>(session); IEnumerable <ControlUser> users = await userQuery.GetItemsAsync(userNames); if (users.Count() == userNames.Length) { ICommand <UserCaseSequencer, UserCaseSequencerId> sequencerCommand = CommandFactory.CreateCommand <ICommand <UserCaseSequencer, UserCaseSequencerId> >(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); IQuery <UserCaseSequencer, UserCaseSequencerId> sequencerQuery = QueryFactory.CreateQuery <IQuery <UserCaseSequencer, UserCaseSequencerId> >(session); sequencers = users.Select((u, i) => new UserCaseSequencer(@case, u, i)); sequencers = await sequencerCommand.SaveOrUpdateCollectionAsync(sequencerQuery, sequencers); @case.NextUserId = sequencers.OrderBy(i => i.Sequence).First().Id.UserId; await caseCommand.UpdateAsync(@case); } else { result = UserMessages.UsersNotExist(GetNotExistUsers(users, userNames)); } } else { result = CaseMessages.CaseNotExist(nameCase); } return(String.IsNullOrEmpty(result) ? new ProcessResult(SequeceMessages.CaseSequenceGenerated(nameCase, sequencers), true) : new ProcessResult(result, false)); }