public async Task <Question> UpdateAsync(Question question, IEnumerable <Answer> newAnswer, Guid userId) { var user = await _userManager.Users.SingleOrDefaultAsync(u => u.Id == userId); if (user == null) { throw new InvalidOperationException("You must be logged in."); } var dbQuestion = _mapper.Map <QuestionEntity>(question); dbQuestion.ModifiedAt = DateTimeOffset.UtcNow; dbQuestion.User = user; _context.Questions.Update(dbQuestion); if (newAnswer.Any()) { var dbAnswers = _mapper.Map <IEnumerable <AnswerEntity> >(newAnswer); dbAnswers.All(answerEntity => { answerEntity.Question = dbQuestion; answerEntity.User = user; return(true); }); _context.Answers.AddRange(dbAnswers); } var updated = await _context.SaveChangesAsync(); if (updated < 1) { throw new InvalidOperationException("Could not update question."); } return(question); }
public async Task <Participant> UpdateAsync(Participant participant) { var dbParticipant = _mapper.Map <ParticipantEntity>(participant); dbParticipant.ModifiedAt = DateTime.Now; _context.Participants.Update(dbParticipant); var updated = await _context.SaveChangesAsync(); if (updated < 1) { throw new InvalidOperationException("Could not update participant."); } return(participant); }
public async Task <bool> AddAsync(List <Event> eventSummaryDetails) { var dbEvents = _mapper.Map <List <EventEntity> >(eventSummaryDetails); dbEvents.All(x => { x.CreatedAt = DateTime.Now; x.ModifiedAt = DateTime.Now; return(true); }); await _context.Events.AddRangeAsync(dbEvents); var created = await _context.SaveChangesAsync(); return(created > 1); }
public static async Task SeedDataAsync(this FmsDbContext context, CancellationToken token) { if (!await context.FacilityStatuses.AnyAsync(token)) { await context.FacilityStatuses.AddRangeAsync(GetFacilityStatuses(), token); } if (!await context.FacilityTypes.AnyAsync(token)) { await context.FacilityTypes.AddRangeAsync(GetFacilityTypes(), token); } if (!await context.OrganizationalUnits.AnyAsync(token)) { await context.OrganizationalUnits.AddRangeAsync(GetOrganizationalUnits(), token); } if (!await context.BudgetCodes.AnyAsync(token)) { await context.BudgetCodes.AddRangeAsync(GetBudgetCodes(), token); } if (!await context.ComplianceOfficers.AnyAsync(token)) { await context.ComplianceOfficers.AddRangeAsync(GetComplianceOfficers(), token); } if (!await context.Cabinets.AnyAsync(token)) { await context.Cabinets.AddRangeAsync(GetCabinets(), token); } if (!await context.Files.AnyAsync(token)) { await context.Files.AddRangeAsync(GetFiles(), token); } if (!await context.Facilities.AnyAsync(token)) { await context.Facilities.AddRangeAsync(GetFacilities(), token); } if (!await context.RetentionRecords.AnyAsync(token)) { await context.RetentionRecords.AddRangeAsync(GetRetentionRecords(), token); } await context.SaveChangesAsync(token); }
public async Task <Guid> AddAsync(Feedback feedback, Guid eventId) { //var user = await _userManager.Users.SingleOrDefaultAsync(u => u.Id == userId); //if (user == null) throw new InvalidOperationException("You must be logged in."); var dbFeedback = _mapper.Map <FeedbackEntity>(feedback); dbFeedback.CreatedAt = DateTime.Now; dbFeedback.ModifiedAt = DateTime.Now; var dbEvent = await _context.Events.SingleOrDefaultAsync(e => e.Id.Equals(eventId)); dbFeedback.Event = dbEvent; await _context.Feedbacks.AddAsync(dbFeedback); var created = await _context.SaveChangesAsync(); if (created < 1) { throw new InvalidOperationException("Could not create feedback."); } return(_mapper.Map <Feedback>(dbFeedback).Id); }
public static async Task AddTestData( FmsDbContext context, UserManager <UserEntity> userManager) { if (context.Questions.Any()) { // Already has data return; } var adminUser = userManager.Users .SingleOrDefault(u => u.Email == "*****@*****.**"); context.Questions.Add(new QuestionEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195976"), Description = "How do you rate the overall event?", Answers = new[] { new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9995971"), Description = "1", Icon = "far fa-angry fa-5x text-red", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195981"), Description = "2", Icon = "far fa-frown fa-5x text-yellow-darker", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195972"), Description = "3", Icon = "far fa-meh fa-5x text-warning", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195961"), Description = "4", Icon = "far fa-smile fa-5x text-lime", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195971"), Description = "5", Icon = "far fa-grin-hearts fa-5x text-green", Active = true, CreatedAt = DateTimeOffset.UtcNow } }, User = adminUser, Active = true, AllowMultipleAnswer = false, FreeTextQuestion = false, CustomQuestion = true, FeedbackType = "participated", CreatedAt = DateTimeOffset.UtcNow }); context.Questions.Add(new QuestionEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195974"), Description = "What did you like about this volunteering activity?", User = adminUser, Active = true, AllowMultipleAnswer = false, FreeTextQuestion = true, CustomQuestion = false, FeedbackType = "participated", CreatedAt = DateTimeOffset.UtcNow }); context.Questions.Add(new QuestionEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195975"), Description = "What can be improved in this volunteering activity?", User = adminUser, Active = true, AllowMultipleAnswer = false, FreeTextQuestion = true, CustomQuestion = false, FeedbackType = "participated", CreatedAt = DateTimeOffset.UtcNow }); context.Questions.Add(new QuestionEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9e9195973"), Description = "Hey there, You had registered for the event on saturday. We would like to know the reason for not joining the event to understand if the team which created the event has some room for improvement in their process, so that we get 100% participation from the registered attendees.", Answers = new[] { new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-25a9e9995971"), Description = "Unexpected Personal Committment", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-26a9e9995971"), Description = "Unexpected Official Work", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-27a9e9995971"), Description = "Even Not What I Expected", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-28a9e9995971"), Description = "Did Not Receive Further Information About The Event", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-29a9e9995971"), Description = "Incorrectly Registered", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-24a9e9995971"), Description = "Do Not Wish to Disclose", Active = true, CreatedAt = DateTimeOffset.UtcNow } }, User = adminUser, Active = true, AllowMultipleAnswer = false, FreeTextQuestion = false, CustomQuestion = false, FeedbackType = "notparticipated", CreatedAt = DateTimeOffset.UtcNow }); context.Questions.Add(new QuestionEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-35a9c9195975"), Description = "Hey there, Please share your feedback for unregistering from the event ?", Answers = new[] { new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-45a9e9995971"), Description = "Unexpected Personal Committment", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-46a9e9995971"), Description = "Unexpected Official Work", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-47a9e9995971"), Description = "Even Not What I Expected", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-48a9e9995971"), Description = "Did Not Receive Further Information About The Event", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-49a9e9995971"), Description = "Incorrectly Registered", Active = true, CreatedAt = DateTimeOffset.UtcNow }, new AnswerEntity { Id = Guid.Parse("ee2b83be-91db-4de5-8122-50a9e9995971"), Description = "Do Not Wish to Disclose", Active = true, CreatedAt = DateTimeOffset.UtcNow } }, User = adminUser, Active = true, AllowMultipleAnswer = false, FreeTextQuestion = false, CustomQuestion = false, FeedbackType = "unregistered", CreatedAt = DateTimeOffset.UtcNow }); await context.SaveChangesAsync(); }