public IActionResult GetEmployeeSurveyConsent([FromBody] EmployeeSurvey model) { if (model == null) { return(BadRequest("Error, Contact your Manager/ Administrator!")); } try { Employee employee = _context.Employees.FirstOrDefault(id => id.Identifier.ToString() == model.EmployeeIdentifier); Project project = _context.Projects.FirstOrDefault(id => id.ProjectIdentifier.ToString() == model.ProjectIdentifier); ProjectParticipant projectParticipant = _context.ProjectParticipants.FirstOrDefault(id => (id.ParticipantId == employee.EmployeeId) && (id.ProjectId == project.ProjectId)); projectParticipant.IsAcknowledged = true; _context.ProjectParticipants.Update(projectParticipant); _context.SaveChanges(); return(Ok()); } catch (Exception Ex) { return(BadRequest("Something bad happened! " + Ex.Message)); } }
public async Task <bool> AddParticipant(string userId, int projectId) { Project project = await GetProjectById(projectId); if (project == null || !project.IsActive) { return(false); } var participant = new ProjectParticipant { UserId = userId, ProjectId = projectId }; try { _context.Add(participant); await _context.SaveChangesAsync(); } catch (DbUpdateException) { return(false); } return(true); }
public async Task <Guid> Handle(CreateProjectParticipantCommand request, CancellationToken cancellationToken) { var entity = new ProjectParticipant { AddedBy = request.AddedBy, ProjectId = request.ProjectId, UserId = request.UserId }; this.context.ProjectParticipants.Add(entity); await this.context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public void AddNewTeamMember(string fName, string lName, string uName, string typeMember, bool hasParticipated) { if (typeMember.Equals("Trainee")) { var part = new ProjectParticipant(fName, lName, uName, hasParticipated); this.teamMembers.Add(part); this.participants.Add(part); } else { this.teamMembers.Add(new TelerikTrainer(fName, lName, uName)); } this.usedResourcesByID[(int)Resource.ResourceType.ProjectParticipant] = true; }
public IActionResult GetEmployeeSurvey([FromBody] EmployeeSurvey model) { if (model == null) { return(BadRequest("Error, Make sure form is complete!")); } try { Employee employee = _context.Employees.FirstOrDefault(id => id.Identifier.ToString() == model.EmployeeIdentifier); Project project = _context.Projects.FirstOrDefault(id => id.ProjectIdentifier.ToString() == model.ProjectIdentifier); ProjectParticipant projectParticipant = _context.ProjectParticipants.FirstOrDefault(id => (id.ParticipantId == employee.EmployeeId) && (id.ProjectId == project.ProjectId)); if ((employee != null) && (project != null)) { var employeeSurvey = new { Name = employee.Name, Surname = employee.Surname, Email = employee.Email, Organization = _context.AssetNodes.FirstOrDefault(id => id.AssetNodeId == employee.AssetNodeId).Name, Root = _context.AssetNodes.FirstOrDefault(id => id.AssetNodeId == _context.AssetNodes.FirstOrDefault(id => id.AssetNodeId == employee.AssetNodeId).RootAssetNodeId).Name, ProjectName = project.Name, ProjectStartDate = project.StartDate.ToString("dd MMM yyyy"), ProjectEndDate = project.EndDate.ToString("dd MMM yyyy"), ProjectType = _context.Surveys.FirstOrDefault(id => id.SurveyId == project.SurveyId).Name, IsParticipated = projectParticipant.IsParticipated, IsAcknowleged = projectParticipant.IsAcknowledged }; return(Ok(employeeSurvey)); } return(Ok()); } catch (Exception Ex) { return(BadRequest("Something bad happened. " + Ex.Message)); } }
public async Task <IActionResult> UpdateProject(Int16 ProjectId, [FromBody] Project item) { if (item == null || item.Id != ProjectId) { return(BadRequest()); } var model = await ApplicationDbContext.Projects.Include(f => f.Financingforms).Include(p => p.Participants).ThenInclude(p => p.Participant).FirstOrDefaultAsync(o => o.Id == ProjectId); if (model == null) { var msg = String.Format(FAILGETENTITYBYID, ProjectId); return(NotFound(msg)); } if (item.Title != null) { model.Title = item.Title; model.Shorttitle = item.Shorttitle; model.Subtitle = item.Subtitle; model.Description = item.Description; model.Startdate = item.Startdate; model.Enddate = item.Enddate; } if (item.Abstract != null) { model.Abstract = item.Abstract; } // budget if (model.Budget != null) { Budget budget; if (model.BudgetId > 0) { budget = ApplicationDbContext.Budgets.FirstOrDefault(m => m.Id == model.BudgetId); } else { budget = new Budget(); } budget.TotalBudget = model.Budget.TotalBudget; budget.ArteveldeBudget = model.Budget.ArteveldeBudget; budget.InvestmentBudget = model.Budget.InvestmentBudget; budget.OperatingBudget = model.Budget.OperatingBudget; budget.StaffBudget = model.Budget.StaffBudget; model.BudgetValidate = item.BudgetValidate; model.Budget = budget; } if (item.Profiles != null) { foreach (var profile in item.Profiles.ToList()) { Profile profile1 = ApplicationDbContext.Profiles.FirstOrDefault(m => m.Id == profile.ProfileId); var af = new ProjectProfile { Project = item, Profile = profile1 }; ApplicationDbContext.ProjectProfile.Add(af); } } if (item.Financingforms != null || item.Participants != null || item.Tags != null || item.Partners != null || item.Links != null) { // many financingform; delete old + add new var oldProjectFinancingforms = ApplicationDbContext.ProjectFinancingform.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldProjectFinancingform in oldProjectFinancingforms) { //model.Financingforms.Remove(oldProjectFinancingform); ApplicationDbContext.Entry(oldProjectFinancingform).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } if (item.Financingforms != null) { foreach (var financingform in item.Financingforms.ToList()) { Financingform financingform1 = ApplicationDbContext.Financingforms.FirstOrDefault(m => m.Id == financingform.FinancingformId); var af = new ProjectFinancingform { Project = item, Financingform = financingform1 }; ApplicationDbContext.ProjectFinancingform.Add(af); } } // many participants; delete old + add new var oldProjectParticipants = ApplicationDbContext.ProjectParticipant.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldProjectParticipant in oldProjectParticipants) { ApplicationDbContext.Entry(oldProjectParticipant).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } if (item.Participants != null) { foreach (var participant in item.Participants.ToList()) { Participant participant1 = ApplicationDbContext.Participants.FirstOrDefault(m => m.Id == participant.ParticipantId); var af = new ProjectParticipant { Project = item, Participant = participant1 }; ApplicationDbContext.ProjectParticipant.Add(af); } } //tags var oldTags = ApplicationDbContext.Tags.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldTag in oldTags) { ApplicationDbContext.Entry(oldTag).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Tag> tags = new List <Tag>(); if (item.Tags != null) { foreach (var tag in item.Tags.ToList()) { var tag1 = new Tag(); tag1.Name = tag.Name; tags.Add(tag1); model.Tags = tags; } } //partners var oldPartners = ApplicationDbContext.Partners.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldPartner in oldPartners) { ApplicationDbContext.Entry(oldPartner).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Partner> partners = new List <Partner>(); if (item.Partners != null) { foreach (var partner in item.Partners.ToList()) { var partner1 = new Partner(); partner1.Name = partner.Name; partners.Add(partner1); model.Partners = partners; } } //links var oldLinks = ApplicationDbContext.Links.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldLink in oldLinks) { ApplicationDbContext.Entry(oldLink).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Link> links = new List <Link>(); if (item.Links != null) { foreach (var link in item.Links.ToList()) { var link1 = new Link(); link1.Name = link.Name; links.Add(link1); model.Links = links; } } } //mediums if (item.Mediums != null) { var oldMediums = ApplicationDbContext.Mediums.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldMedia in oldMediums) { ApplicationDbContext.Entry(oldMedia).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Media> mediums = new List <Media>(); foreach (var media in item.Mediums.ToList()) { var media1 = new Media(); media1.Image = media.Image; media1.TypeMedia = media.TypeMedia; mediums.Add(media1); model.Mediums = mediums; } } ApplicationDbContext.Projects.Attach(model); ApplicationDbContext.Entry(model).State = EntityState.Modified; await ApplicationDbContext.SaveChangesAsync(); return(new NoContentResult()); }
public async Task <IActionResult> UpdateProjectMetadata(Int16 ProjectId, [FromBody] Project item) { if (item == null || item.Id != ProjectId) { return(BadRequest()); } var model = await ApplicationDbContext.Projects.Include(f => f.Financingforms) .Include(p => p.Participants).ThenInclude(p => p.Participant).FirstOrDefaultAsync(o => o.Id == ProjectId); if (model == null) { var msg = String.Format(FAILGETENTITYBYID, ProjectId); return(NotFound(msg)); } model.PartnerValidate = item.PartnerValidate; model.ParticipantValidate = item.ParticipantValidate; model.FinancingformValidate = item.FinancingformValidate; model.LinkValidate = item.LinkValidate; // many financingform; delete old + add new var oldProjectFinancingforms = ApplicationDbContext.ProjectFinancingform.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldProjectFinancingform in oldProjectFinancingforms) { //model.Financingforms.Remove(oldProjectFinancingform); ApplicationDbContext.Entry(oldProjectFinancingform).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } if (item.Financingforms != null) { foreach (var financingform in item.Financingforms.ToList()) { Financingform financingform1 = ApplicationDbContext.Financingforms.FirstOrDefault(m => m.Id == financingform.FinancingformId); var af = new ProjectFinancingform { Project = item, Financingform = financingform1 }; ApplicationDbContext.ProjectFinancingform.Add(af); } } // many participants; delete old + add new var oldProjectParticipants = ApplicationDbContext.ProjectParticipant.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldProjectParticipant in oldProjectParticipants) { ApplicationDbContext.Entry(oldProjectParticipant).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } if (item.Participants != null) { foreach (var participant in item.Participants.ToList()) { Participant participant1 = ApplicationDbContext.Participants.FirstOrDefault(m => m.Id == participant.ParticipantId); var af = new ProjectParticipant { Project = item, Participant = participant1 }; ApplicationDbContext.ProjectParticipant.Add(af); } } //tags var oldTags = ApplicationDbContext.Tags.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldTag in oldTags) { ApplicationDbContext.Entry(oldTag).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Tag> tags = new List <Tag>(); if (item.Tags != null) { foreach (var tag in item.Tags.ToList()) { var tag1 = new Tag(); tag1.Name = tag.Name; tags.Add(tag1); model.Tags = tags; } } //partners var oldPartners = ApplicationDbContext.Partners.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldPartner in oldPartners) { ApplicationDbContext.Entry(oldPartner).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Partner> partners = new List <Partner>(); if (item.Partners != null) { foreach (var partner in item.Partners.ToList()) { var partner1 = new Partner(); partner1.Name = partner.Name; partners.Add(partner1); model.Partners = partners; } } //links var oldLinks = ApplicationDbContext.Links.Where(m => m.ProjectId == model.Id).ToList(); foreach (var oldLink in oldLinks) { ApplicationDbContext.Entry(oldLink).State = EntityState.Deleted; ApplicationDbContext.SaveChanges(); } List <Link> links = new List <Link>(); if (item.Links != null) { foreach (var link in item.Links.ToList()) { var link1 = new Link(); link1.Name = link.Name; links.Add(link1); model.Links = links; } } ApplicationDbContext.Projects.Attach(model); ApplicationDbContext.Entry(model).State = EntityState.Modified; await ApplicationDbContext.SaveChangesAsync(); return(new NoContentResult()); }
public IActionResult SaveProject([FromBody] Models.Project model) { if (model == null) { return(BadRequest("Error, Make sure form is complete!")); } try { Project projectChecker = _context.Projects.FirstOrDefault(id => (id.Name.ToUpper() == model.Name.ToUpper()) && (id.ClientId == model.ClientId)); if (projectChecker != null) { return(BadRequest("Project with this name for this client already exists.")); } DateTime firstReminder = model.FirstReminder.AddHours(model.FirstReminderTime.Hours).AddMinutes(model.FirstReminderTime.Minutes); DateTime secondReminder = model.SecondReminder.AddHours(model.SecondReminderTime.Hours).AddMinutes(model.SecondReminderTime.Minutes); DateTime escalate = model.Escalate.AddHours(model.EscalateTime.Hours).AddMinutes(model.EscalateTime.Minutes); if (model.StartDate > model.EndDate) { return(BadRequest("Make sure Start Date is less than End Date")); } if ((firstReminder >= secondReminder) || (firstReminder >= escalate)) { return(BadRequest("Make sure First Reminder is always less than other reminders.")); } else if ((secondReminder <= firstReminder) || (secondReminder >= escalate)) { return(BadRequest("Make sure Second Reminder is always less than Escalate reminder and bigger than First Reminder.")); } else if ((escalate <= firstReminder) || (secondReminder >= escalate)) { return(BadRequest("Make sure Escalate Reminder is always less than other reminders.")); } Project project = new Project(); project.Name = model.Name; project.ClientId = model.ClientId; project.TenantId = model.TenantId; project.SurveyId = model.SurveyId; project.Reference = model.Reference; project.DateStamp = model.DateStamp; project.FirstReminder = firstReminder; project.SecondReminder = secondReminder; project.Escalate = escalate; project.EscalateEmail = model.EscalateEmail; project.StartDate = model.StartDate; project.EndDate = model.EndDate; project.DateStamp = DateTime.Now; project.ProjectIdentifier = Guid.NewGuid(); project.AssetNodeId = model.AssetNodeId; _context.Projects.Add(project); _context.SaveChanges(); //Add clients participants to the project List <ClientEmployee> clientEmployees = _context.ClientEmployees.Where(id => id.ClientId == model.ClientId).ToList(); foreach (var item in clientEmployees) { ProjectParticipant projectParticipant = new ProjectParticipant(); projectParticipant.ParticipantId = item.EmployeeId; projectParticipant.ProjectId = project.ProjectId; _context.ProjectParticipants.Add(projectParticipant); _context.SaveChanges(); } return(Ok()); } catch (Exception Ex) { return(BadRequest("Something bad happened! " + Ex.Message)); } }