public async Task <IHttpActionResult> Update([FromBody] GradeDTO grade) { var response = new OverviewResponse <GradeOverview>(); try { Grade newGrade = _mapper.Map <GradeDTO, Grade>(grade); var result = _gradeService.Update(newGrade); if (!result) { response.IsSuccess = false; response.Errors.Add("Grade was not saved"); } var overviews = GetGradeOverview(); response.IsSuccess = !response.Errors.Any(); response.Overview = overviews; } catch (Exception ex) { response.IsSuccess = false; response.Errors.Add(ex.Message); response.Errors.Add("-----------------------------------"); response.Errors.Add(ex.InnerException.Message); var overviews = GetGradeOverview(); response.Overview = overviews; return(Ok(response)); } //Call overview var hubContext = GlobalHost.ConnectionManager.GetHubContext <ClientHub>(); hubContext.Clients.All.reloadGrade(response); return(Ok(response)); }
public static List <GradeDTO> GradeList() { List <GradeDTO> lstGrade = new List <GradeDTO>(); LinqToSqlDataContext db = new LinqToSqlDataContext(); var Grades = (from dg in db.Device_Grades where dg.Dev_Active == true orderby dg.Dev_Grade ascending select new { Grade = dg.Dev_Grade }).Distinct(); foreach (var grade in Grades) { GradeDTO gra = new GradeDTO(); gra.Grade = grade.Grade; lstGrade.Add(gra); } db.Dispose(); return(lstGrade); }
private void updateGrade() { try { if (!txtGradeId.Text.Trim().Equals(string.Empty)) { GradeDTO oGradeDTO = new GradeDTO(); oGradeDTO.GradeId = Convert.ToInt16(txtGradeId.Text.Trim()); oGradeDTO.SubjectId = cmbSubject.SelectedValue.ToString(); oGradeDTO.Description = txtDescription.Text.Trim(); oGradeDTO.LowerLimit = Convert.ToInt16(txtLowerLimit.Text.Trim()); oGradeDTO.UpperLimit = Convert.ToInt16(txtUpperLimit.Text.Trim()); oGradeDTO.ModifiedBy = "Kaveen"; oGradeDTO.ModifiedDateTime = DateTime.Now; if (oGradeBL.UpdateGrade(oGradeDTO)) { ClearControls(); filterBySubjectId(); MessageBox.Show("Record Updated successfully.!"); } } else { txtGradeId.Focus(); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Posts a new grade /// </summary> /// <param name="model"></param> /// <returns></returns> public GradeDTO AddGrade(AddGradeViewModel model) { // get the student from the ssn, throw exception if they don't exist Person student = _persons.GetStudentBySSN(model.SSN); // get the assignment from the assignmentID, throw exception if it doesn't exist Assignment assignment = _assignments.GetAssignmentByID(model.AssignmentID); // Checking if the grade already exists var studentGrade = _grades.All().SingleOrDefault(grade => grade.AssignmentID == model.AssignmentID && grade.StudentSSN == model.SSN); if (studentGrade != null) { throw new ArgumentException(ErrorCodes.ASSIGNMENT_GRADE_ALREADY_EXISTS); } Grade grad = new Grade { AssignmentID = model.AssignmentID, StudentSSN = model.SSN, GradeValue = model.GradeValue }; _grades.Add(grad); _uow.Save(); GradeDTO gradeTransfer = grad.GetGradeDTO(); gradeTransfer.AssignmentName = assignment.Name; gradeTransfer.StudentID = student.ID; return(gradeTransfer); }
public ActionResult <GradeDTO> Post(GradeDTO grade) { try { NovaGradeCommand command = new NovaGradeCommand() { Grade = new Grade( grade.CodGrade, grade.Turma, grade.Disciplina, grade.Curso, grade.CodFuncionario ) }; grade = this.mediator.Send(command).Result; return(new CreatedResult("", grade)); } catch (Exception ex) { if (ex.InnerException is ConflitException) { return(Conflict(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else if (ex.InnerException is NaoEncontradoException) { return(NotFound(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } else { return(UnprocessableEntity(new { Erros = new string[] { ex.InnerException?.Message ?? ex.Message } })); } } }
public GradeDTO CreateGrade(GradeDTO newGrade) { Grade grade = Utilities.ConverterDTO.SimpleDTOConverter <Grade>(newGrade); db.GradesRepository.Insert(grade); db.Save(); return(newGrade); }
public static GradeDTO GetGradeDTO(Grade Grade) { GradeDTO GradeDTO = new GradeDTO(); GradeDTO.IdGrade = Grade.IdGrade; GradeDTO.Level = Grade.Level; return(GradeDTO); }
public async Task AddNewGrade() { GradeDTO gradeDTO = new GradeDTO() { Marks = 12, Subject = "JJ" }; await _dataAccessGet.AddNewGrade(gradeDTO, "147137f8-c3d9-4854-bb3b-af9be026cc69"); }
async public Task AddNewGrade(GradeDTO gradeDTO, string studentId) { var student = await _applicationDbContext.Students.Where(x => x.ID == studentId).Include(x => x.Grades).FirstOrDefaultAsync(); var grade = _mapper.Map <GradeDTO, Grade>(gradeDTO); student.Grades.Add(grade); await _applicationDbContext.SaveChangesAsync(); }
public GradeDTO CreateGrade() { var grade = new GradeDTO { GradeId = _gradeService.GetNewGradeId() }; return(grade); }
public Grade Map(GradeDTO grade) { return(new Grade { Id = grade.Id, Name = grade.Name, ClassTeacherId = grade.ClassTeacherId }); }
public bool UpdateGrade(GradeDTO oGradeDTO) { bool result = false; try { sb.Clear(); sb.Append("UPDATE [Grade]"); sb.Append(" SET "); sb.Append(" Description=?Description,"); sb.Append(" SubjectId=?SubjectId,"); sb.Append(" LowerLimit=?LowerLimit,"); sb.Append(" UpperLimit=?UpperLimit,"); sb.Append(" ModifiedBy=?ModifiedBy,"); sb.Append(" ModifiedDateTime=?ModifiedDateTime"); sb.Append(" WHERE GradeId =?GradeId"); using (CloudConnection connection = new CloudConnection(DMSSWE.Common.ConnectionString)) { connection.CommandText = sb.ToString(); connection.Parameters.Clear(); connection.Parameters.Add(new Parameter { Name = "Description", Value = oGradeDTO.Description }); connection.Parameters.Add(new Parameter { Name = "SubjectId", Value = oGradeDTO.SubjectId }); connection.Parameters.Add(new Parameter { Name = "LowerLimit", Value = oGradeDTO.LowerLimit }); connection.Parameters.Add(new Parameter { Name = "UpperLimit", Value = oGradeDTO.UpperLimit }); connection.Parameters.Add(new Parameter { Name = "ModifiedBy", Value = oGradeDTO.ModifiedBy }); connection.Parameters.Add(new Parameter { Name = "ModifiedDateTime", Value = oGradeDTO.ModifiedDateTime }); connection.Parameters.Add(new Parameter { Name = "GradeId", Value = oGradeDTO.GradeId }); if (connection.ExecuteQuery() > 0) { result = true; } } } catch (Exception ex) { throw ex; } return(result); }
public void UpdateCatalogueGrade(Grade grade, GradeDTO gradeDTO, int schoolId) { Domain.Grade updateGrade = _context.Grades.FirstOrDefault(g => g.Id == grade.Id); updateGrade.StudentId = gradeDTO.StudentId; updateGrade.Mark = gradeDTO.Mark; updateGrade.CourseId = gradeDTO.CourseId; updateGrade.MentorId = gradeDTO.MentorId; updateGrade.Date = gradeDTO.Date; _context.SaveChanges(); }
public GradeViewModel Map(GradeDTO grade) { return(new GradeViewModel { Id = grade.Id, Name = grade.Name, ClassTeacherId = grade?.ClassTeacherId.Value, ClassTeacher = new TeacherViewModel { Name = grade?.ClassTeacher?.Name, Surname = grade?.ClassTeacher?.Surname, SecondName = grade?.ClassTeacher?.SecondName } }); }
public void DeleteGrade(Grade grade) { var gradeDTO = new GradeDTO(); Mapper.Map(grade, gradeDTO); var existingEntity = _gradeRepository.Single(x => x.ID == gradeDTO.ID); if (existingEntity != null) { _gradeRepository.Delete(existingEntity); } }
public IHttpActionResult DeleteGrade(int id) { try { GradeDTO retVal = service.DeleteGrade(id); logger.Info("Admin deleted grade"); return(Ok(retVal)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public GradeDTO DeleteGrade(int id) { Grade grade = db.GradesRepository.GetByID(id); if (grade == null) { throw new GradesNotFoundException($"No grade wuth id {id}"); } db.GradesRepository.Delete(id); db.Save(); GradeDTO gradeDTO = Utilities.ConverterDTO.SimpleDTOConverter <GradeDTO>(grade); return(gradeDTO); }
public IHttpActionResult PutGrade(GradeDTO gradeDTO) { try { Grade grade = mapper.Map <Grade>(gradeDTO); repository.Update(grade); repository.Save(); } catch (Exception e) { return(Ok(e)); } return(Ok()); }
public IActionResult UpdateCatalogueGrade(int schoolId, int catalogueId, int gradeId, [FromBody] GradeDTO gradeDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Grade grade = _schoolRepository.GetCatalogueGrade(gradeId, schoolId, catalogueId); if (grade == null) { return(NotFound()); } _schoolRepository.UpdateCatalogueGrade(grade, gradeDTO, schoolId); return(NoContent()); }
public void AddGrade() { // Arrange: AddGradeViewModel gradeModel = new AddGradeViewModel { GradeValue = 8, SSN = "2233882299", AssignmentID = 4 }; // Act: GradeDTO addedGrade = _service.AddGrade(gradeModel); // Assert: Assert.AreEqual(gradeModel.SSN, addedGrade.StudentSSN); Assert.AreEqual(gradeModel.GradeValue, addedGrade.GradeValue); Assert.AreEqual(gradeModel.AssignmentID, addedGrade.AssignmentID); }
public List <GradeDTO> SearchGrade(string subjectId, string searchText) { List <GradeDTO> oGradeList = new List <GradeDTO>(); try { sb.Clear(); sb.Append("SELECT GradeId, Description, LowerLimit, UpperLimit"); sb.Append(" FROM [Grade]"); sb.Append(" WHERE SubjectId=?SubjectId AND Description LIKE '%' + ?Description + '%'"); using (CloudConnection connection = new CloudConnection(DMSSWE.Common.ConnectionString)) { connection.CommandText = sb.ToString(); connection.Parameters.Clear(); connection.Parameters.Add(new Parameter { Name = "SubjectId", Value = subjectId }); connection.Parameters.Add(new Parameter { Name = "Description", Value = searchText }); using (IDataReader dr = connection.ExecuteReader()) { if (dr != null) { while (dr.Read()) { GradeDTO oGrade = new GradeDTO(); oGrade.GradeId = Convert.ToInt16(dr["GradeId"]); oGrade.Description = dr["Description"].ToString(); oGrade.LowerLimit = Convert.ToInt16(dr["LowerLimit"].ToString()); oGrade.UpperLimit = Convert.ToInt16(dr["UpperLimit"].ToString()); oGradeList.Add(oGrade); } } } } } catch (Exception ex) { throw ex; } return(oGradeList); }
public IHttpActionResult EditGradeAdmin(int id, string teacherId, [FromBody] GradeCreateAndEditDTO dto) { if (!ModelState.IsValid) { logger.Warn("Bad model state."); return(BadRequest()); } try { GradeDTO retVal = service.EditGrade(id, teacherId, dto); logger.Info("Admin edited grade. status OK"); return(Ok(retVal)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void SaveGrade(Grade grade) { var gradeDTO = new GradeDTO(); GradeDTO existingEntity = null; Mapper.Map(grade, gradeDTO); if (gradeDTO.ID != 0) { existingEntity = _gradeRepository.Single(x => x.ID == gradeDTO.ID); } if (existingEntity != null) { _unitOfWork.Entry(existingEntity).CurrentValues.SetValues(gradeDTO); } else { _gradeRepository.Add(gradeDTO); } }
public static GradeDTO GradeToGradeDTO(Grade grade) { GradeDTO retVal = new GradeDTO() { Id = grade.Id, Value = grade.Value, DateOfGrading = grade.DateOfGrading, Subject = SchoolSubjectToSchoolSubjectDTOConverters .SchoolSubjectToSchoolSubjectDTO(grade.SchoolClassTeacherSchoolSubject.TeacherSchoolSubject.SchoolSubject), GradingTeacher = UserToUserDTOConverters .UserToUserSimpleViewDTO(grade.SchoolClassTeacherSchoolSubject.TeacherSchoolSubject.Teacher), Student = UserToUserDTOConverters .StudentToStudentBasicDTO(grade.Student) }; logger.Info("Converting Grade to GradeDTO."); return(retVal); }
public IActionResult CreateCatalogueGrade(int schoolId, int catalogueId, [FromBody] GradeDTO gradeDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Student student = _schoolRepository.GetStudent(gradeDTO.StudentId, schoolId); Course course = _schoolRepository.GetCourse(gradeDTO.CourseId, schoolId); Mentor mentor = _schoolRepository.GetMentor(gradeDTO.MentorId, schoolId); Grade grade = new Grade() { Student = student, Mark = gradeDTO.Mark, Course = course, Mentor = mentor, Date = gradeDTO.Date }; _schoolRepository.AddCatalogueGrade(grade, schoolId, catalogueId); return(CreatedAtRoute("GetCatalogueGrade", new { schoolId, catalogueId, gradeId = grade.Id }, grade)); }
public IHttpActionResult EditGradeTeacher(int id, [FromBody] GradeCreateAndEditDTO dto) { string teacherId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value; if (!ModelState.IsValid) { logger.Warn("Bad model state."); return(BadRequest()); } try { GradeDTO retVal = service.EditGrade(id, teacherId, dto); logger.Info("Teacher edited grade. status OK"); return(Ok(retVal)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult post([FromBody] GradeDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { //var idToken = HttpContext.GetTokenAsync(JwtBearerDefaults.AuthenticationScheme, "access_token"); //var token = idToken.Result; var grade = _gradeService.CreateGrade(value, ""); if (grade != null) { return(Ok(grade)); } return(BadRequest(new { message = "Cannot Create Grade" })); } catch (Exception e) { return(BadRequest(e)); } }
public GradeDTO CreateGrade(GradeDTO gradeDTO, string token) { try { var repo = _unitOfWork.GetRepository <Grade>(); var newvalue = Mapper.Map <Grade>(gradeDTO); newvalue.CreationDate = DateTime.Now; newvalue.GradeGUID = Guid.NewGuid(); if (newvalue.GradeCode == null) { newvalue.GradeCode = newvalue.GradeId; } //if (newvalue.GradeSymbol == null) newvalue.GradeSymbol = newvalue.GradeId; //newvalue.CreatedBy = _appUserService.GetUserId(token); repo.Add(newvalue); repo.SaveChanges(); return(Mapper.Map <GradeDTO>(newvalue)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool InsertGrade(GradeDTO oGradeDTO) { bool result = false; try { sb.Clear(); sb.Append("INSERT INTO [Grade]"); sb.Append(" VALUES ("); sb.Append(" ?SubjectId,"); sb.Append(" ?GradeId,"); sb.Append(" ?Description,"); sb.Append(" ?LowerLimit,"); sb.Append(" ?UpperLimit,"); sb.Append(" ?CreatedBy,"); sb.Append(" ?CreatedDateTime,"); sb.Append(" ?ModifiedBy,"); sb.Append(" ?ModifiedDateTime"); sb.Append(" )"); using (CloudConnection connection = new CloudConnection(DMSSWE.Common.ConnectionString)) { connection.CommandText = sb.ToString(); connection.Parameters.Clear(); connection.Parameters.Add(new Parameter { Name = "SubjectId", Value = oGradeDTO.SubjectId }); connection.Parameters.Add(new Parameter { Name = "GradeId", Value = oGradeDTO.GradeId }); connection.Parameters.Add(new Parameter { Name = "Description", Value = oGradeDTO.Description }); connection.Parameters.Add(new Parameter { Name = "LowerLimit", Value = oGradeDTO.LowerLimit }); connection.Parameters.Add(new Parameter { Name = "UpperLimit", Value = oGradeDTO.UpperLimit }); connection.Parameters.Add(new Parameter { Name = "CreatedBy", Value = oGradeDTO.CreatedBy }); connection.Parameters.Add(new Parameter { Name = "CreatedDateTime", Value = oGradeDTO.CreatedDateTime }); connection.Parameters.Add(new Parameter { Name = "ModifiedBy", Value = oGradeDTO.ModifiedBy }); connection.Parameters.Add(new Parameter { Name = "ModifiedDateTime", Value = oGradeDTO.ModifiedDateTime }); if (connection.ExecuteQuery() > 0) { result = true; } } } catch (Exception ex) { throw ex; } return(result); }
public GradeViewModel Map(GradeDTO grade) { return(new GradeViewModel { Id = grade.Id }); }
public IList<GradeDTO> GetGrades(Guid commodityId, Guid storeID) { var gradeList = new List<GradeDTO>(); var commodityTransfer = _commodityTransferRepository.GetAll(); foreach (CommodityTransferNote sourcingDocument in commodityTransfer.Where(n => n.DocumentIssuerCostCentre.Id.Equals(storeID))) { if (sourcingDocument.Status != DocumentSourcingStatus.Approved) continue; foreach (var source in sourcingDocument.LineItems.Where(l => l.Commodity.Id.Equals(commodityId) && l.LineItemStatus == SourcingLineItemStatus.New).Select(p => p.CommodityGrade.Id).Distinct()) { var CommodityGrade = _commodityRepository.GetGradeByGradeId(source); if(gradeList.Select(k=>k.Id).Distinct().Contains(CommodityGrade.Id)) continue; var grade = new GradeDTO() { Id = CommodityGrade.Id, Name = CommodityGrade.Name }; gradeList.Add(grade); } } return gradeList; }
public IList<LineItemDTO> GetLineItems(Guid storeId, Guid commodityId, Guid gradeID) { var lineItemList = new List<LineItemDTO>(); var commodityTransfer = _commodityTransferRepository.GetAll(); foreach (CommodityTransferNote sourcingDocument in commodityTransfer.Where(n => n.DocumentIssuerCostCentre.Id.Equals(storeId))) { if (sourcingDocument.Status != DocumentSourcingStatus.Approved) continue; foreach (var items in sourcingDocument.LineItems) { if (items.Commodity.Id.Equals(commodityId) && items.CommodityGrade.Id.Equals(gradeID) && items.LineItemStatus == SourcingLineItemStatus.New) { var store = _storeRepository.GetById(storeId); var itemStore = new StoreDTO() { Id = store.Id, Name = store.Name }; var commodity = new CommodityDTO() { Id = items.Commodity.Id, Name = items.Commodity.Name }; var grade = new GradeDTO() { Id = items.CommodityGrade.Id, Name = items.CommodityGrade.Name }; var item = new LineItemDTO() { BatchNo = items.ContainerNo, Store = itemStore, Commodity = commodity, Grade = grade, IsSelected = false, Id = items.Id, Weight = items.Weight }; lineItemList.Add(item); } } } return lineItemList; }