public async Task AddActivityRecordCommitment(ActivityRecordCommitmentViewModel activityRecordCommitment) { var queryFactory = _dataAccess.GetQueryFactory(_connectionString); var activityQuery = queryFactory.Query(TableConstants.ActivityRecordCommitmentTable); var id = await activityQuery.InsertGetIdAsync <int>(new Dictionary <string, object> { { ActivityRecordCommitmentConstants.ActivityRecordId, activityRecordCommitment.MyActivityRecordId }, { ActivityRecordCommitmentConstants.Commitment, activityRecordCommitment.MyCommitment }, { ActivityRecordCommitmentConstants.CommitmentDate, activityRecordCommitment.MyCommitmentDate }, { ActivityRecordCommitmentConstants.Responsible, activityRecordCommitment.MyResponsible } }); activityRecordCommitment.MyId = id; }
public async Task <ActivityRecordViewModel> GetActivityRecord(int id) { var queryFactory = _dataAccess.GetQueryFactory(_connectionString); var activityQuery = queryFactory.Query(TableConstants.ActivityRecordTable); var membersQuery = queryFactory.Query(TableConstants.ActivityRecordMemberTable); var commitmentQuery = queryFactory.Query(TableConstants.ActivityRecordCommitmentTable); var projectQuery = queryFactory.Query(TableConstants.ProjectTable); var item = (await activityQuery.Where(ActivityRecordConstants.Id, id) .Include(TableConstants.ProjectTable, projectQuery, ProjectConstants.ProjectId, ActivityRecordConstants.ProjectId) .IncludeMany(TableConstants.ActivityRecordMemberTable, membersQuery, $"{ActivityRecordMemberConstants.ActivityRecordId}", $"{ActivityRecordConstants.Id}") .IncludeMany(TableConstants.ActivityRecordCommitmentTable, commitmentQuery, $"{ActivityRecordCommitmentConstants.ActivityRecordId}", $"{ActivityRecordConstants.Id}").GetAsync()) .Cast <IDictionary <string, object> >().ToList().First(); var project = (IDictionary <string, object>)item[TableConstants.ProjectTable]; var activityRecord = new ActivityRecordViewModel { MyId = (int)item[ActivityRecordConstants.Id], MyDate = (DateTime)item[ActivityRecordConstants.Date], MyDurationHours = (double?)item[ActivityRecordConstants.DurationHours], MyNotes = (string)item[ActivityRecordConstants.Notes], MyPlace = (string)item[ActivityRecordConstants.Place], MyTitle = (string)item[ActivityRecordConstants.Title], MySecurityReflection = (string)item[ActivityRecordConstants.SecurityReflection], MyProjectName = (string)project[ProjectConstants.ProjectName], MyProjectId = (int)project[ProjectConstants.ProjectId], MyProjectCode = (string)project[ProjectConstants.ProjectCode] }; var members = (IEnumerable <IDictionary <string, object> >)item[TableConstants.ActivityRecordMemberTable]; foreach (var member in members) { var activityRecordMember = new ActivityRecordMemberViewModel { MyId = (int)member[ActivityRecordMemberConstants.Id], MyEmail = (string)member[ActivityRecordMemberConstants.Email], MyRut = (string)member[ActivityRecordMemberConstants.Rut], MyName = (string)member[ActivityRecordMemberConstants.Name], MySurname = (string)member[ActivityRecordMemberConstants.Surname], MyEnterprise = (string)member[ActivityRecordMemberConstants.Enterprise], MyBminingId = (int?)member[ActivityRecordMemberConstants.BminingId], IsBminingMember = (ulong)member[ActivityRecordMemberConstants.IsBminingMember] == 1, }; activityRecord.OurMembers.Add(activityRecordMember); } var commitments = (IEnumerable <IDictionary <string, object> >)item[TableConstants.ActivityRecordCommitmentTable]; foreach (var commitment in commitments) { var activityRecordCommitment = new ActivityRecordCommitmentViewModel { MyId = (int)commitment[ActivityRecordCommitmentConstants.Id], MyResponsible = (string)commitment[ActivityRecordCommitmentConstants.Responsible], MyCommitment = (string)commitment[ActivityRecordCommitmentConstants.Commitment], MyCommitmentDate = (DateTime)commitment[ActivityRecordCommitmentConstants.CommitmentDate], MyStatus = (ActivityRecordStatusEnum)commitment[ActivityRecordCommitmentConstants.ActivityRecordStatus] }; activityRecord.OurCommitments.Add(activityRecordCommitment); } return(activityRecord); }