public async Task <bool> SetSubCompetetionParticipants(int subCompetetionID, List <SubCompetetionParticipants> participants) { Models.Competetion.SubCompetetion subCompetetion = await _context.SubCompetetions.FindAsync(subCompetetionID); if (subCompetetion == null) { return(false); } using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { foreach (SubCompetetionParticipants participant in participants) { if (participant.IsChecked) { await this.AddTotalMark(subCompetetionID, participant.ParticipantID.Value, subCompetetion.IsTeam); } else { await this.DeleteTotalMark(subCompetetionID, participant.ParticipantID.Value); } } await _context.SaveChangesAsync(); scope.Complete(); return(true); } }
public async Task <IActionResult> PutSubCompetetionType(int id, SubCompetetionType subCompetetionType) { if (id != subCompetetionType.SubCompetetionTypeID) { return(BadRequest()); } _context.Entry(subCompetetionType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubCompetetionTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSpecialization(int id, Specialization specialization) { if (id != specialization.SpecializationID) { return(BadRequest()); } _context.Entry(specialization).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpecializationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutImage(int id, Image image) { if (id != image.ImageId) { return(BadRequest()); } _context.Entry(image).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ImageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <Models.Competetion.Question> AddQuestion(APIModel.Competetion.Question question) { Models.Competetion.Question ques = this.QuestionMap(question); _context.Questions.Add(ques); await _context.SaveChangesAsync(); return(ques); }
public async Task <bool> Http() { try { IList <MainCompetetion> main = await _context.MainCompetetions.Include(p => p.SubCompetetions).ToListAsync(); //main.FirstOrDefault().SubCompetetions.FirstOrDefault().SubCompetetionName = "ruba"; main.FirstOrDefault().SubCompetetions = new List <SubCompetetion> { new SubCompetetion { SubCompetetionID = 8, SubCompetetionName = "اختبار المناطق", SubCompetetionTypeID = 1, SubCompetetionDate = new DateTime(2019, 3, 20), IsTeam = false, IsNewerParticipants = false, CompetetionStatistics = new CompetetionStatistic { FemaleSuccessfulPercentage = 70, MaleSuccessfulPercentage = 30, TotalSuccessfulPercentage = 40, } }, new SubCompetetion { SubCompetetionName = "اختبار التالي", SubCompetetionTypeID = 1, SubCompetetionDate = new DateTime(2019, 3, 20), IsTeam = false, IsNewerParticipants = false, CompetetionStatistics = new CompetetionStatistic { FemaleSuccessfulPercentage = 70, MaleSuccessfulPercentage = 30, TotalSuccessfulPercentage = 40, } } }; await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); } return(true); }
async Task <bool> IImageService.SaveImage(List <IFormFile> Image, int StudentId) { Image image = new Image(); image.StudentID = StudentId; foreach (var item in Image) { if (item.Length > 0) { using (var stream = new MemoryStream()) { await item.CopyToAsync(stream); image.StudentImage = stream.ToArray(); } } } _context.Image.Add(image); await _context.SaveChangesAsync(); return(true); }
private async Task UpdateTotalMark(Models.Competetion.TotalMark totalMark) { _context.Entry(totalMark).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public async Task CompleteAsync() { await _context.SaveChangesAsync(); }