public async Task <ActionResult <CodeLab> > Update(string id, [FromBody] CodeLabForUpdateDto codeLabForUpdateDto) { CodeLab codeLabChanges = _mapper.Map <CodeLab>(codeLabForUpdateDto); CodeLab updatedCodeLab = await _codeLabsService.Update(id, codeLabChanges); return(Ok(updatedCodeLab)); }
public async Task <CodeLabForReturnDto> AcceptApplication(string codeLabId, string applicantId, string userId) { CodeLab codeLab = await _codeLabs.Find(Builders <CodeLab> .Filter.Eq(x => x.Id, codeLabId)).FirstOrDefaultAsync(); if (!codeLab.MemberIds.Contains(userId)) { throw new UnauthorizedAccessException(); } // Application application = codeLab.Applications.Find(app => app.Id == applicantId); var updateResult = await _codeLabs.FindOneAndUpdateAsync( Builders <CodeLab> .Filter.Eq(x => x.Id, codeLabId), Builders <CodeLab> .Update.Push(x => x.MemberIds, applicantId), new FindOneAndUpdateOptions <CodeLab> { ReturnDocument = ReturnDocument.After } ); var filter = Builders <CodeLab> .Filter; var fullFilter = filter.And( filter.Eq(x => x.Id, codeLabId), filter.ElemMatch(x => x.Applications, a => a.ApplicantId == applicantId)); var update = Builders <CodeLab> .Update; var applicationStatusSetter = update.Set("Applications.$.Status", "accepted"); await _codeLabs.UpdateOneAsync(fullFilter, applicationStatusSetter); return(await GetOne(codeLabId)); }
public async Task <IActionResult> Create(CodeLabForCreateDto codeLabForCreateDto) { string currUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; CodeLab codeLabToCreate = _mapper.Map <CodeLab>(codeLabForCreateDto); codeLabToCreate.LeadId = currUserId; codeLabToCreate.MemberIds = new List <string> { currUserId }; codeLabToCreate.Applications = new List <Application> { }; codeLabToCreate.Chat = new Chat(); await _codeLabsService.Create(codeLabToCreate); return(Ok(codeLabToCreate)); }
public async Task <CodeLabForReturnDto> RejectApplication(string codeLabId, string applicantId, string userId) { CodeLab codeLab = await _codeLabs.Find(Builders <CodeLab> .Filter.Eq(x => x.Id, codeLabId)).FirstOrDefaultAsync(); if (!codeLab.MemberIds.Contains(userId)) { throw new UnauthorizedAccessException(); } var filter = Builders <CodeLab> .Filter; var fullFilter = filter.And( filter.Eq(x => x.Id, codeLabId), filter.ElemMatch(x => x.Applications, a => a.ApplicantId == applicantId)); var update = Builders <CodeLab> .Update; var applicationStatusSetter = update.Set("Applications.$.Status", "rejected"); await _codeLabs.UpdateOneAsync(fullFilter, applicationStatusSetter); return(await GetOne(codeLabId)); }
public static BsonDocument getUpdate(CodeLab codeLab) { string mongoQuery = ""; if (codeLab.Title != null) { mongoQuery += ", Title: '" + codeLab.Title + "'"; } if (codeLab.Description != null) { mongoQuery += ", Description: '" + codeLab.Description + "' "; } if (codeLab.LookingFor != null) { mongoQuery += ", LookingFor: '" + codeLab.LookingFor + "' "; } // if (codeLab.FinalGoalURL != null) mongoQuery += ", FinalGoalURL: '" + codeLab.FinalGoalURL + "' "; return(createUpdate("{" + mongoQuery.Substring(1) + "}")); }
public async Task <CodeLabForReturnDto> GetOne(string id) { CodeLab codeLab = await _codeLabs.Find(Builders <CodeLab> .Filter.Eq(x => x.Id, id)).FirstOrDefaultAsync(); CodeLabForReturnDto codeLabToReturnDto = _mapper.Map <CodeLabForReturnDto>(codeLab); var applications = new List <ApplicationForReturnDto>(); foreach (Application application in codeLab.Applications) { User user = await _users.Find(Builders <User> .Filter.Eq(x => x.Id, application.ApplicantId)).FirstOrDefaultAsync(); UserForReturnDto userForReturn = _mapper.Map <UserForReturnDto>(user); ApplicationForReturnDto applicationForReturnDto = _mapper.Map <ApplicationForReturnDto>(application); applicationForReturnDto.Applicant = userForReturn; applications.Add(applicationForReturnDto); } codeLabToReturnDto.Applications = applications; return(codeLabToReturnDto); }
public async Task <CodeLab> Update(string id, CodeLab codeLab) { var updateList = new List <UpdateDefinition <CodeLab> >(); if (codeLab.Title != null) { updateList.Add(Builders <CodeLab> .Update.Set("Title", codeLab.Title)); } if (codeLab.Description != null) { updateList.Add(Builders <CodeLab> .Update.Set("Description", codeLab.Description)); } if (codeLab.Goal != null) { updateList.Add(Builders <CodeLab> .Update.Set("Goal", codeLab.Goal)); } if (codeLab.LookingFor != null) { updateList.Add(Builders <CodeLab> .Update.Set("LookingFor", codeLab.LookingFor)); } if (codeLab.Joining != null) { updateList.Add(Builders <CodeLab> .Update.Set("Joining", codeLab.Joining)); } var finalUpdate = Builders <CodeLab> .Update.Combine(updateList); CodeLab result = await _codeLabs.FindOneAndUpdateAsync( Builders <CodeLab> .Filter.Eq(x => x.Id, id), finalUpdate, new FindOneAndUpdateOptions <CodeLab> { ReturnDocument = ReturnDocument.After } ); return(result); }
public Task Create(CodeLab codeLab) { return(_codeLabs.InsertOneAsync(codeLab)); }