public IActionResult CreateDictionary(DictionaryDTO dictionary) { _loggerManager.Info($"CreateDictionary for {dictionary.Title} is requested"); Response.StatusCode = StatusCodes.Status202Accepted; if (ModelState.IsValid) { var result = _dictionaryRepository.Create(dictionary, HttpContext.GetUserId()); if (result) { Response.StatusCode = StatusCodes.Status201Created; _loggerManager.Info($"CreateDictionary for {dictionary.Title} successfully created a dictionary"); } else { _loggerManager.Warn($"CreateDictionary for {dictionary.Title} was unable to create a dictionary"); } } else { _loggerManager.Warn($"CreateDictionary for {dictionary.Title} was invalid"); } return(PartialView("~/Views/Manage/Partials/_NewDictionary.cshtml")); }
public async Task <HttpResponseMessage> PutDictionary(DictionaryDTO dictionary) { if (dictionary == null) { _logger.Info( $"DictionaryController.PutDictionary [ClientAddress: {GetClientAddress()}]"); throw new ApplicationException("Object DictionaryDTO is null."); } _logger.Info( "DictionaryController.PutDictionary [" + $"ClientAddress: {GetClientAddress()}, DictionaryName: {dictionary.Name}, Version: {dictionary.Version}]"); try { var res = await _service.ChangeDictionaryAsync(dictionary.Name, dictionary.Version, dictionary); return(Request.CreateResponse(HttpStatusCode.OK, res)); } catch (Exception ex) { _logger.Error(GetErrorMessage(ex)); return(Request.CreateResponse(HttpStatusCode.InternalServerError, GetErrorMessage(ex))); } }
public static DictionaryDC MappingDTOtoDC(DictionaryDTO dictionaryDTO) { MapperConfiguration configDTOtoDC = new MapperConfiguration(cfg => { cfg.CreateMap <DictionaryDTO, DictionaryDC>(); }); IMapper iMapper = configDTOtoDC.CreateMapper(); return(iMapper.Map <DictionaryDTO, DictionaryDC>(dictionaryDTO)); }
public ActionResult Create(DictionaryDTO dto) { if (ModelState.IsValid) { dto.CreatedBy = dto.ModifiedBy = this.User.Id; this._IDictionaryService.Create(dto); return(RedirectToAction("Index")); } return(View()); }
/// <summary> /// Change or create new dictionary. /// </summary> /// <param name="dictionaryName">Name of the dictionary.</param> /// <param name="version">The version.</param> /// <param name="dictionary">The dictionary.</param> /// <returns>System.Threading.Tasks.Task<DictionariesModel.Dictionary>.</returns> public async Task <DictionaryDTO> ChangeDictionaryAsync( string dictionaryName, string version, DictionaryDTO dictionary) { _logger.Info($"BLService.ChangeDictionaryNameAsync [" + $"DictionaryName: {dictionaryName}, Version: {version}, Value:{dictionary}]"); try { var oldDict = await _dataRepository.GetDictionaryWithoutItemsAsync(dictionaryName, version); if (oldDict == null) { return(await CreateNewDictionaryAsync(dictionary)); } oldDict.Name = dictionary.Name; oldDict.Metadata = dictionary.Metadata?.ToString(); oldDict.Version = dictionary.Version; if (dictionary.Items != null && dictionary.Items.Count != 0) { oldDict.Items = dictionary.Items; foreach (var oldDictItem in oldDict.Items) { oldDictItem.DictionaryId = oldDict.Id; } } var changedDictionary = await _dataRepository.ChangeDictionaryAsync(oldDict); return(ConvertToDictionaryDto(changedDictionary)); } catch (SqlException ex) { if (ex.Number == DuplicateKeyNumber) { throw new Exception("Cannot insert duplicate"); } _logger.Error($"ChangeDictionaryName Exception:{ex} value:{dictionary}"); throw; } catch (Exception ex) { _logger.Error($"CreateNewDictionary Exception:{ex} value:{dictionary}"); throw; } }
public ActionResult Edit(DictionaryDTO dto) { if (ModelState.IsValid) { dto.ModifiedBy = this.User.Id; this._IDictionaryService.Update(new DictionaryDTOList { dto }); return(RedirectToAction("Index")); } return(View()); }
/// <summary> /// Method to convert Dictionary object into List of custom created dictionary object /// </summary> /// <param name="dictionary"></param> /// <returns></returns> internal List <DictionaryDTO> MapDictToList(Dictionary <string, string> dictionary) { List <DictionaryDTO> listDicDto = new List <DictionaryDTO>(); foreach (var item in dictionary) { DictionaryDTO dtoDict = new DictionaryDTO(); dtoDict.Key = new MyString(); dtoDict.Key.VarName = item.Key; dtoDict.Value = new MyString(); dtoDict.Value.VarName = item.Value; listDicDto.Add(dtoDict); } return(listDicDto); }
public void AddDictionaryTest() { string name = "currency"; string version = "1.0.0"; //string id = "1"; DictionaryDTO dict = new DictionaryDTO { Name = name, Metadata = new JObject(), Version = version }; service.CreateNewDictionaryAsync(dict); var a = service.GetDictionaryAsync(name, version, true); string json = JsonConvert.SerializeObject(a, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); }
public async Task <HttpResponseMessage> PutDictionary( string dictionaryName, string version, DictionaryDTO dictionary) { _logger.Info( "DictionaryController.PutDictionary [" + $"ClientAddress: {GetClientAddress()}, DictionaryName: {dictionaryName}, Version: {version}]"); try { var res = await _service.ChangeDictionaryAsync(dictionaryName, version, dictionary); return(Request.CreateResponse(HttpStatusCode.OK, res)); } catch (Exception ex) { _logger.Error(GetErrorMessage(ex)); return(Request.CreateResponse(HttpStatusCode.InternalServerError, GetErrorMessage(ex))); } }
public bool Create(DictionaryDTO newDictionary, int userId) { var dictionary = Mapper.Map <Dictionary>(newDictionary); dictionary.CreatedAt = DateTime.Now; dictionary.UpdatedAt = DateTime.Now; dictionary.CreatedBy = userId; dictionary.UpdatedBy = userId; try { Create(dictionary); Context.SaveChanges(); } catch (Exception) { return(false); } return(true); }
/// <summary> /// create new dictionary as an asynchronous operation. /// </summary> /// <param name="dictionary">The dictionary.</param> /// <returns>Task<Dictionary>.</returns> /// <exception cref="System.Exception">Cannot insert duplicate</exception> public async Task <DictionaryDTO> CreateNewDictionaryAsync(DictionaryDTO dictionary) { _logger.Info($"BLService.CreateNewDictionary [Value:{dictionary}]"); try { var dictionaryForSave = new Dictionary { Id = dictionary.Id, Items = dictionary.Items, Metadata = dictionary.Metadata?.ToString(), Name = dictionary.Name, Version = dictionary.Version }; var result = await _dataRepository.AddAsync(dictionaryForSave); return(ConvertToDictionaryDto(result)); } catch (SqlException ex) { if (ex.Number == DuplicateKeyNumber) { throw new Exception("Cannot insert duplicate"); } _logger.Error($"CreateNewDictionary Exception:{ex} value:{dictionary}"); throw; } catch (Exception ex) { _logger.Error($"CreateNewDictionary Exception:{ex} value:{dictionary}"); throw; } }
public ActionResult <string> SearchImage([FromBody] DictionaryDTO translateData) //FROM TO: IMAGE { string reqimagetext = OCR.OCR.GetText(translateData.Image); return(Ok(UserInterface.GetWord(reqimagetext, translateData.Lang.ToLower()))); }
public ActionResult <string> SearchText([FromBody] DictionaryDTO translateData) //FROM TO: TEXT kachvash tekst, izvejda { return(Ok(UserInterface.GetWord(translateData.Text, translateData.Lang.ToLower()))); }
public ActionResult Post([FromBody] DictionaryDTO input) { AccessGuardian(new AccessRole(Roles.AccessUser)); return(JsonHelper.Success(DictionariesService.InsertOrUpdate(input))); }
private void CalculateStrata(int strata) { try { int yyVal = 0; int ynVal = 0; int nyVal = 0; int nnVal = 0; this.strata = strata; Grid grd = FindChild <Grid>(stackPanel, "grdTables" + strata); TextBox txtYesYesVal = FindChild <TextBox>(grd, "txtYesYesVal" + strata); TextBox txtYesNoVal = FindChild <TextBox>(grd, "txtYesNoVal" + strata); TextBox txtNoYesVal = FindChild <TextBox>(grd, "txtNoYesVal" + strata); TextBox txtNoNoVal = FindChild <TextBox>(grd, "txtNoNoVal" + strata); TextBlock txtYesTotalVal = FindChild <TextBlock>(grd, "txtYesTotalVal" + strata); TextBlock txtNoTotalVal = FindChild <TextBlock>(grd, "txtNoTotalVal" + strata); TextBlock txtYesYesRow = FindChild <TextBlock>(grd, "txtYesYesRow" + strata); TextBlock txtYesNoRow = FindChild <TextBlock>(grd, "txtYesNoRow" + strata); TextBlock txtNoYesRow = FindChild <TextBlock>(grd, "txtNoYesRow" + strata); TextBlock txtNoNoRow = FindChild <TextBlock>(grd, "txtNoNoRow" + strata); TextBlock txtTotalTotalVal = FindChild <TextBlock>(grd, "txtTotalTotalVal" + strata); TextBlock txtTotalYesVal = FindChild <TextBlock>(grd, "txtTotalYesVal" + strata); TextBlock txtYesYesCol = FindChild <TextBlock>(grd, "txtYesYesCol" + strata); TextBlock txtNoYesCol = FindChild <TextBlock>(grd, "txtNoYesCol" + strata); TextBlock txtTotalNoVal = FindChild <TextBlock>(grd, "txtTotalNoVal" + strata); TextBlock txtYesNoCol = FindChild <TextBlock>(grd, "txtYesNoCol" + strata); TextBlock txtNoNoCol = FindChild <TextBlock>(grd, "txtNoNoCol" + strata); TextBlock txtTotalYesRow = FindChild <TextBlock>(grd, "txtTotalYesRow" + strata); TextBlock txtTotalNoRow = FindChild <TextBlock>(grd, "txtTotalNoRow" + strata); TextBlock txtYesTotalCol = FindChild <TextBlock>(grd, "txtYesTotalCol" + strata); TextBlock txtNoTotalCol = FindChild <TextBlock>(grd, "txtNoTotalCol" + strata); TextBlock txtTotalYesCol = FindChild <TextBlock>(grd, "txtTotalYesCol" + strata); TextBlock txtTotalNoCol = FindChild <TextBlock>(grd, "txtTotalNoCol" + strata); TextBlock txtYesTotalRow = FindChild <TextBlock>(grd, "txtYesTotalRow" + strata); TextBlock txtNoTotalRow = FindChild <TextBlock>(grd, "txtNoTotalRow" + strata); TextBlock txtTotalTotalCol = FindChild <TextBlock>(grd, "txtTotalTotalCol" + strata); TextBlock txtTotalTotalRow = FindChild <TextBlock>(grd, "txtTotalTotalRow" + strata); TextBlock txtChiSqCorP = FindChild <TextBlock>(stackPanel, "txtChiSqCorP" + strata); TextBlock txtChiSqCorVal = FindChild <TextBlock>(stackPanel, "txtChiSqCorVal" + strata); TextBlock txtChiSqManP = FindChild <TextBlock>(stackPanel, "txtChiSqManP" + strata); TextBlock txtChiSqManVal = FindChild <TextBlock>(stackPanel, "txtChiSqManVal" + strata); TextBlock txtChiSqUncP = FindChild <TextBlock>(stackPanel, "txtChiSqUncP" + strata); TextBlock txtChiSqUncVal = FindChild <TextBlock>(stackPanel, "txtChiSqUncVal" + strata); TextBlock txtOddsRatioEstimate = FindChild <TextBlock>(stackPanel, "txtOddsRatioEstimate" + strata); TextBlock txtOddsRatioLower = FindChild <TextBlock>(stackPanel, "txtOddsRatioLower" + strata); TextBlock txtOddsRatioUpper = FindChild <TextBlock>(stackPanel, "txtOddsRatioUpper" + strata); TextBlock txtMidPEstimate = FindChild <TextBlock>(stackPanel, "txtMidPEstimate" + strata); TextBlock txtMidPLower = FindChild <TextBlock>(stackPanel, "txtMidPLower" + strata); TextBlock txtMidPUpper = FindChild <TextBlock>(stackPanel, "txtMidPUpper" + strata); TextBlock txtFisherLower = FindChild <TextBlock>(stackPanel, "txtFisherLower" + strata); TextBlock txtFisherUpper = FindChild <TextBlock>(stackPanel, "txtFisherUpper" + strata); TextBlock txtRiskDifferenceEstimate = FindChild <TextBlock>(stackPanel, "txtRiskDifferenceEstimate" + strata); TextBlock txtRiskDifferenceLower = FindChild <TextBlock>(stackPanel, "txtRiskDifferenceLower" + strata); TextBlock txtRiskDifferenceUpper = FindChild <TextBlock>(stackPanel, "txtRiskDifferenceUpper" + strata); TextBlock txtRiskRatioEstimate = FindChild <TextBlock>(stackPanel, "txtRiskRatioEstimate" + strata); TextBlock txtRiskRatioLower = FindChild <TextBlock>(stackPanel, "txtRiskRatioLower" + strata); TextBlock txtRiskRatioUpper = FindChild <TextBlock>(stackPanel, "txtRiskRatioUpper" + strata); TextBlock txtFisherExact = FindChild <TextBlock>(stackPanel, "txtFisherExact" + strata); TextBlock txtMidPExact = FindChild <TextBlock>(stackPanel, "txtMidPExact" + strata); TextBlock txtFisherExact2P = FindChild <TextBlock>(stackPanel, "txtFisherExact2P" + strata); int.TryParse(txtYesYesVal.Text, out yyVal); int.TryParse(txtYesNoVal.Text, out ynVal); int.TryParse(txtNoYesVal.Text, out nyVal); int.TryParse(txtNoNoVal.Text, out nnVal); DictionaryDTO dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "0").ToMyString(); dto.Value = yyVal.ToString().ToMyString(); strataVals.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "1").ToMyString(); dto.Value = ynVal.ToString().ToMyString(); strataVals.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "2").ToMyString(); dto.Value = nyVal.ToString().ToMyString(); strataVals.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "3").ToMyString(); dto.Value = nnVal.ToString().ToMyString(); strataVals.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "0").ToMyString(); dto.Value = (txtYesYesVal.Text.Length > 0).ToString().ToMyString(); strataActive.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "1").ToMyString(); dto.Value = (txtYesNoVal.Text.Length > 0).ToString().ToMyString(); strataActive.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "2").ToMyString(); dto.Value = (txtNoYesVal.Text.Length > 0).ToString().ToMyString(); strataActive.Add(dto); dto = new DictionaryDTO(); dto.Key = (strata.ToString() + "3").ToMyString(); dto.Value = (txtNoNoVal.Text.Length > 0).ToString().ToMyString(); strataActive.Add(dto); //strataVals[strata][0] = yyVal; //strataVals[strata][1] = ynVal; //strataVals[strata][2] = ; //strataVals[strata][3] = ; //strataActive[strata][0] = (txtYesYesVal.Text.Length > 0); //strataActive[strata][1] = (txtYesNoVal.Text.Length > 0); //strataActive[strata][2] = (txtNoYesVal.Text.Length > 0); //strataActive[strata][3] = (txtNoNoVal.Text.Length > 0); int ytVal = yyVal + ynVal; int ntVal = nyVal + nnVal; int ttVal = ytVal + ntVal; int tyVal = yyVal + nyVal; int tnVal = ynVal + nnVal; double yyRowPct = 0; double ynRowPct = 0; double nyRowPct = 0; double nnRowPct = 0; double yyColPct = 0; double nyColPct = 0; double ynColPct = 0; double nnColPct = 0; double tyRowPct = 0; double tnRowPct = 0; double ytColPct = 0; double ntColPct = 0; if (ytVal != 0) { yyRowPct = 1.0 * yyVal / ytVal; ynRowPct = 1.0 * ynVal / ytVal; } if (ntVal != 0) { nyRowPct = 1.0 * nyVal / ntVal; nnRowPct = 1.0 * nnVal / ntVal; } if (tyVal != 0) { yyColPct = 1.0 * yyVal / tyVal; nyColPct = 1.0 * nyVal / tyVal; } if (tnVal != 0) { ynColPct = 1.0 * ynVal / tnVal; nnColPct = 1.0 * nnVal / tnVal; } if (ttVal != 0) { tyRowPct = 1.0 * tyVal / ttVal; tnRowPct = 1.0 * tnVal / ttVal; ytColPct = 1.0 * ytVal / ttVal; ntColPct = 1.0 * ntVal / ttVal; } txtYesTotalVal.Text = ytVal.ToString(); txtNoTotalVal.Text = ntVal.ToString(); txtYesYesRow.Text = yyRowPct.ToString("P"); txtYesNoRow.Text = ynRowPct.ToString("P"); txtNoYesRow.Text = nyRowPct.ToString("P"); txtNoNoRow.Text = nnRowPct.ToString("P"); txtTotalTotalVal.Text = ttVal.ToString(); txtTotalYesVal.Text = tyVal.ToString(); txtYesYesCol.Text = yyColPct.ToString("P"); txtNoYesCol.Text = nyColPct.ToString("P"); txtTotalNoVal.Text = tnVal.ToString(); txtYesNoCol.Text = ynColPct.ToString("P"); txtNoNoCol.Text = nnColPct.ToString("P"); txtTotalYesRow.Text = tyRowPct.ToString("P"); txtTotalNoRow.Text = tnRowPct.ToString("P"); txtYesTotalCol.Text = ytColPct.ToString("P"); txtNoTotalCol.Text = ntColPct.ToString("P"); txtTotalYesCol.Text = (1).ToString("P"); txtTotalNoCol.Text = (1).ToString("P"); txtYesTotalRow.Text = (1).ToString("P"); txtNoTotalRow.Text = (1).ToString("P"); txtTotalTotalCol.Text = (1).ToString("P"); txtTotalTotalRow.Text = (1).ToString("P"); statcalcViewModel.GetStatCalc2x2(ytVal, ntVal, tyVal, tnVal, yyVal, ynVal, nyVal, nnVal, strataActive, strataVals); statcalcViewModel.SingleTableLoadedEvent += new EventHandler <SimpleMvvmToolkit.NotificationEventArgs <Exception> >(statcalcViewModel_SingleTableLoadedEvent); } catch (Exception ex) { // } }
public int InsertOrUpdate(DictionaryDTO dictionaryVo) { using (var transaction = Context.Database.BeginTransaction()) { try { var dictionary = Mapper.Map <Dictionary>(dictionaryVo); if (dictionary.Id > 0) { Context.Entry(dictionary).State = EntityState.Modified; DictionariesRepository.Update(dictionary); } else { dictionary.Date = DateTime.Now; dictionary.ParentDictionaryId = null; DictionariesRepository.Insert(dictionary); } DictionariesRepository.Save(); dictionaryVo.TranslationList.ToList().ForEach(x => x.DictionaryId = dictionary.Id); var translations = dictionaryVo.TranslationList.Select(x => x.Id).ToList(); var currentTranslations = TranslationsRepository .GetAll() .Where(x => x.DictionaryId == dictionary.Id) .ToList(); var ids = currentTranslations.Select(x => x.Id).ToList(); var toDelete = currentTranslations.Where(x => !translations.Contains(x.Id)).ToList(); var toAdd = dictionaryVo.TranslationList?.Where(x => !ids.Contains(x.Id)).ToList() ?? new List <Translation>(); var toUpdate = dictionaryVo.TranslationList?.Where(x => ids.Contains(x.Id)).ToList() ?? new List <Translation>(); foreach (var trans in toDelete) { GameSessionTranslationsRepository.DeleteByTranslationId(trans.Id); TranslationsRepository.Delete(trans); } foreach (var trans in toUpdate) { TranslationsRepository.Update(trans); } foreach (var trans in toAdd) { TranslationsRepository.Insert(trans); } TranslationsRepository.Save(); transaction.Commit(); return(dictionary.Id); } catch (Exception) { transaction.Rollback(); return(-1); } } }
public DictionaryDTO Create(DictionaryDTO dto) { return(base.Create <DictionaryDTO, Dictionary>(dto , _IDictionaryRepository , dtoAction => { })); }