//Update Standard (async) public async Task <StandardDTO> UpdateStandardAsync(StandardDTO modelDTO) { try { using (var unitOfWork = unitOfWorkFactory.Create()) { StandardModel model = _Mapper_ToModel.Map <StandardDTO, StandardModel>(modelDTO); bool result = unitOfWork.StandardRepository.Update(model); StandardDTO modelRTN = null; if (result) { await unitOfWork.SaveChangesAsync(); modelRTN = _Mapper_ToDTO.Map <StandardModel, StandardDTO>(model); } return(modelRTN); } } catch (Exception ex) { LogException(ex); throw ex; } }
//below code will fetch only Standard LIst not based on classtype public List <StandardDTO> Standard() { using (IDbSvc dbSvc = new DbSvc(_configSvc)) { try { dbSvc.OpenConnection(); MySqlCommand command = new MySqlCommand(); command.CommandText = "select StandardId,StandardName from standard where Active=1"; command.Connection = dbSvc.GetConnection() as MySqlConnection; _dtData = new DataTable(); MySqlDataAdapter msDa = new MySqlDataAdapter(command); msDa.Fill(_dtData); List <StandardDTO> lstStandard = new List <StandardDTO>(); if (_dtData != null && _dtData.Rows.Count > 0) { StandardDTO standardDTO = null; foreach (DataRow dr in _dtData.Rows) { standardDTO = new StandardDTO(); standardDTO.StandardId = (int)dr["StandardId"]; standardDTO.StandardName = dr["StandardName"].ToString(); lstStandard.Add(standardDTO); } } return(lstStandard); } catch (Exception exp) { throw exp; } } }
// return standardlist not based on classtype public SelectList getStandardDropDown() { List <StandardDTO> rDto = _ddlRepo.Standard(); StandardDTO blank = new StandardDTO(); blank.StandardId = -1; blank.StandardName = ""; rDto.Insert(0, blank); return(new SelectList(rDto, "StandardId", "StandardName")); }
public async Task <IHttpActionResult> GetStandard(int id) { StandardDTO dto = await StandardService.SearchSingleStandardByIdAsync(id); if (dto != null) { return(Ok(dto)); } else { return(NotFound()); } }
private static StandardDTO Map(Standard from) { try { var to = new StandardDTO(); to.StandardId = from.StandardId; to.StandardName = from.StandardName; return(to); } catch (Exception ex) { Logs.LogError(ex); return(null); } }
public async Task <IHttpActionResult> UpdateStandard([FromBody] StandardDTO StandardModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var updatedStandard = await StandardService.UpdateStandardAsync(StandardModel); if (updatedStandard != null) { return(Ok(updatedStandard)); } else { return(NotFound()); } }
public async Task <IHttpActionResult> AddStandard([FromBody] StandardDTO StandardModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newStandardId = await StandardService.AddStandardAsync(StandardModel); if (newStandardId != 0) { return(Ok(newStandardId)); } else { return(NotFound()); } }
//Add Standard (async) public async Task <int> AddStandardAsync(StandardDTO modelDTO) { try { using (var unitOfWork = unitOfWorkFactory.Create()) { StandardModel model = _Mapper_ToModel.Map <StandardDTO, StandardModel>(modelDTO); unitOfWork.StandardRepository.Add(model); //unitOfWork.Repository.Add<StandardModel>(model); await unitOfWork.SaveChangesAsync(); return(model.StandardId); } } catch (Exception ex) { LogException(ex); throw ex; } }