internal DictionaryDto Map(DictionaryDto a, LanguageTextDto p) { // Terminating call. Since we can return null from this function // we need to be ready for PetaPoco to callback later with null // parameters if (a == null) { return(Current); } // Is this the same DictionaryItem as the current one we're processing if (Current != null && Current.UniqueId == a.UniqueId) { // Yes, just add this LanguageTextDto to the current DictionaryItem's collection Current.LanguageTextDtos.Add(p); // Return null to indicate we're not done with this DictionaryItem yet return(null); } // This is a different DictionaryItem to the current one, or this is the // first time through and we don't have a Tab yet // Save the current DictionaryItem var prev = Current; // Setup the new current DictionaryItem Current = a; Current.LanguageTextDtos = new List <LanguageTextDto>(); Current.LanguageTextDtos.Add(p); // Return the now populated previous DictionaryItem (or null if first time through) return(prev); }
public async Task <ActionResult> SubscribeAsync(Guid userId, [FromBody] DictionaryDto dictionary) { _service.Token = await getAccessToken(); await _service.SubscribeAsync(userId, _mapper.Map <Dictionary>(dictionary)); return(Ok()); }
public async Task <ActionResult> UpdateAsync([FromBody] DictionaryDto dictionary) { _service.Token = await getAccessToken(); await _service.UpdateAsync(_mapper.Map <Dictionary>(dictionary)); return(Ok()); }
public async Task <ActionResult> InsertAsync([FromBody] DictionaryDto dictionary) { _service.Token = await getAccessToken(); var inserted = await _service.InsertAsync(_mapper.Map <Dictionary>(dictionary)); return(CreatedAtAction("GetDictionaryById", new { id = inserted.Id }, inserted));; }
/// <summary> /// 新增字典 /// </summary> /// <param name="dto"></param> /// <returns></returns> public IHttpActionResult Post([FromBody] DictionaryDto dto) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } _dictionary.CreatDictionary(dto); return(Ok()); }
public void EditDictionary(DictionaryDto dto) { var entity = Mapper.Map <DictionaryDto, Dictionary>(dto); using (var dbScope = _dbScopeFactory.Create()) { var db = dbScope.DbContexts.Get <FireProjDbContext>(); db.Update(entity, r => new { r.Description, ModifyBy = r.ModifyId, r.ModifyDate, r.Name, r.ParentId, r.Value }); db.SaveChanges(); } }
protected IDictionaryItem ConvertFromDto(DictionaryDto dto) { var entity = DictionaryItemFactory.BuildEntity(dto); entity.Translations = dto.LanguageTextDtos.EmptyNull() .Where(x => x.LanguageId > 0) .Select(x => DictionaryTranslationFactory.BuildEntity(x, dto.UniqueId)) .ToList(); return(entity); }
public void CreatDictionary(DictionaryDto dto) { var entity = Mapper.Map <DictionaryDto, Dictionary>(dto); entity.CreateDate = DateTime.Now; using (var dbScope = _dbScopeFactory.Create()) { var db = dbScope.DbContexts.Get <FireProjDbContext>(); db.Dictionary.Add(entity); db.SaveChanges(); } }
public IDictionaryItem BuildEntity(DictionaryDto dto) { var item = new DictionaryItem(dto.Parent, dto.Key) { Id = dto.PrimaryKey, Key = dto.UniqueId }; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 item.ResetDirtyProperties(false); return(item); }
public async Task Load() { dic_Genre generalGenre = new dic_Genre(); generalGenre.name = "All/Any"; dic_Product_type generalProductType = new dic_Product_type(); generalProductType.name = "All/Any"; dic_condition generalCondition = new dic_condition(); generalCondition.name = "All/Any"; using (var client = new HttpClient()) { URLBuilder url = new URLBuilder("/api/Dictionary/"); var request = new HttpRequestMessage() { RequestUri = new Uri(url.URL), Method = HttpMethod.Get, }; var response = await client.SendAsync(request); var contents = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { return; } DictionaryDto result = JsonConvert.DeserializeObject <DictionaryDto>(contents); IEnumerable <GenreDto> genres = result.Genres; Genres.Add(new GenreWrapper(generalGenre)); foreach (GenreDto g in genres) { GenreWrapper wrap = g.createGenre(); Genres.Add(wrap); } IEnumerable <ConditionDto> conditions = result.Conditions; Conditions.Add(new ConditionWrapper(generalCondition)); foreach (ConditionDto c in conditions) { Conditions.Add(c.createCondition()); } IEnumerable <ProductTypeDto> productTypes = result.ProductTypes; ProductTypes.Add(new ProductTypeWrapper(generalProductType)); foreach (var p in productTypes) { ProductTypes.Add(p.createProductType()); } } }
public static string GetDictionaryText(IEnumerable <DictionaryDto> dictionaries, int tag, string value) { string ret = ""; DictionaryDto dictionaryDto = dictionaries.Where(d => d.Tag == tag).FirstOrDefault(); if (dictionaryDto != null) { DictionaryValueDto dictionaryValueDto = dictionaryDto.Values.Where(d => d.Value == value).FirstOrDefault(); if (dictionaryValueDto != null) { ret = dictionaryValueDto.Text; } } return(ret); }
public async Task <IHttpActionResult> Get() { var conditions = _conditionAssembler.EntityToDto(await _conditionService.GetData(null)); var genres = _genreAssembler.EntityToDto(await _genreService.GetData(null)); var productTypes = _productTypeAssembler.EntityToDto(await _productTypeService.GetData(null)); var dto = new DictionaryDto() { Conditions = conditions, Genres = genres, ProductTypes = productTypes }; return(Ok(dto)); }
public static string GetDictionaryText(IEnumerable <DictionaryDto> dictionaries, int tag, string value) { string ret = ""; DictionaryDto dictionaryDto = dictionaries.Where(d => d.Tag == tag).FirstOrDefault(); if (dictionaryDto != null) { DictionaryValueDto dictionaryValueDto = dictionaryDto.Values.Where(d => d.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (dictionaryValueDto != null) { ret = dictionaryValueDto.Text; } } return(ret); }
public Result <DictionaryDto> Get(string key, string callback = "") { Result <DictionaryDto> result = new Result <DictionaryDto>(); try { DictionaryDto dictionaryDto = dictionaryBLL.getByKey(key); result.succeed(dictionaryDto); } catch (Exception e) { result.fail(e.Message); } return(result); }
/// <summary> /// 根据id编辑字典信息 /// </summary> /// <param name="id"></param> /// <param name="dto"></param> /// <returns></returns> public IHttpActionResult Put(int id, [FromBody] DictionaryDto dto) { //参数验证 if (id == 0) { ModelState.AddModelError("id", "id不允许为空"); return(BadRequest(ModelState)); } if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } dto.Id = id; _dictionary.EditDictionary(dto); return(Ok()); }
public ActionResult Edit(int id) { var dto = CommonContract.Dictionarys.Where(c => c.Id == id).Select(m => new DictionaryDto { Id = m.Id, Name = m.Name, Value = m.Value, SortCode = m.SortCode, ParentId = m.Parent.Id, ParentName=m.Parent.Name }).SingleOrDefault(); if (dto == null) dto = new DictionaryDto(); return View(dto); }
public ActionResult Edit(int id) { var dto = CommonContract.Dictionarys.Where(c => c.Id == id).Select(m => new DictionaryDto { Id = m.Id, Name = m.Name, Value = m.Value, SortCode = m.SortCode, ParentId = m.Parent.Id, ParentName = m.Parent.Name }).SingleOrDefault(); if (dto == null) { dto = new DictionaryDto(); } return(View(dto)); }
public static IDictionaryItem BuildEntity(DictionaryDto dto) { var item = new DictionaryItem(dto.Parent, dto.Key); try { item.DisableChangeTracking(); item.Id = dto.PrimaryKey; item.Key = dto.UniqueId; // reset dirty initial properties (U4-1946) item.ResetDirtyProperties(false); return(item); } finally { item.EnableChangeTracking(); } }
public IDictionaryItem BuildEntity(DictionaryDto dto) { var item = new DictionaryItem(dto.Parent, dto.Key); try { item.DisableChangeTracking(); item.Id = dto.PrimaryKey; item.Key = dto.UniqueId; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 item.ResetDirtyProperties(false); return(item); } finally { item.EnableChangeTracking(); } }
protected IDictionaryItem ConvertFromDto(DictionaryDto dto) { var factory = new DictionaryItemFactory(); var entity = factory.BuildEntity(dto); var list = new List <IDictionaryTranslation>(); foreach (var textDto in dto.LanguageTextDtos) { if (textDto.LanguageId <= 0) { continue; } var translationFactory = new DictionaryTranslationFactory(dto.UniqueId); list.Add(translationFactory.BuildEntity(textDto)); } entity.Translations = list; return(entity); }
public HttpResponseMessage GrammarSuggestions([FromBody] DictionaryDto _DictionaryObj) { List <Suggestions> _SuggestionsObj = new List <Suggestions>(); try { if (string.IsNullOrEmpty(_DictionaryObj.text)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Messages.Bad_request_grammar)); } else { _SuggestionsObj = GrammarService.GrammarSuggestionsService(_DictionaryObj.text); return(Request.CreateResponse <List <Suggestions> >(HttpStatusCode.OK, _SuggestionsObj)); } } catch (Exception Ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Ex.Message)); } }
public HttpResponseMessage BulkChangeGrammar([FromBody] DictionaryDto _DictionaryObj) { Response _ResponseObj = new Response(); try { if (string.IsNullOrEmpty(_DictionaryObj.text)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Messages.Bad_request_grammar)); } else { _ResponseObj = GrammarService.BulkChangeGrammarService(_DictionaryObj.text); return(Request.CreateResponse <Response>(HttpStatusCode.OK, _ResponseObj)); } } catch (Exception Ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Ex.Message)); } }
public ListResultDto <GetDictionary> GetDictionaryToChildren(DictionaryDto input) { List <Dictionary> list = new List <Dictionary>(); var id = input.ParentID;//获取子父节点 if (id == 0) { var demos = _dictionary.GetAll().Where(t => t.Id == input.Id).ToList(); foreach (var item in demos) { Dictionary node = new Dictionary(); node.Id = item.Id; node.ParentID = item.ParentID != null ? item.ParentID : 0; node.Title = item.Title; node.Value = item.Value; node.Note = item.Note; node.Code = item.Code; node.Other = item.Other; node.Sort = item.Sort; list.Add(node); } } var demo = _dictionary.GetAll().Where(t => t.ParentID == id).ToList();//查询子节点 foreach (var item in demo) { Dictionary node = new Dictionary(); node.Id = item.Id; node.ParentID = item.ParentID != null ? item.ParentID : 0; node.Title = item.Title; node.Value = item.Value; node.Note = item.Note; node.Code = item.Code; node.Other = item.Other; node.Sort = item.Sort; list.Add(node); } return(new ListResultDto <GetDictionary>(ObjectMapper.Map <List <GetDictionary> >(list))); }
protected IDictionaryItem ConvertFromDto(DictionaryDto dto, ILanguage[] allLanguages) { var factory = new DictionaryItemFactory(); var entity = factory.BuildEntity(dto); var list = new List <IDictionaryTranslation>(); foreach (var textDto in dto.LanguageTextDtos) { //Assuming this is cached! var language = allLanguages.FirstOrDefault(x => x.Id == textDto.LanguageId); if (language == null) { continue; } var translationFactory = new DictionaryTranslationFactory(dto.UniqueId, language); list.Add(translationFactory.BuildEntity(textDto)); } entity.Translations = list; return(entity); }
public ListResultDto <GetDictionaryOutput> GetDictionariesByParentID(DictionaryDto input) { var data = (from a in _dictionary.GetAll() where a.ParentID == input.Id select new GetDictionaryOutput { Id = a.Id, ParentID = a.ParentID, Title = a.Title, Value = a.Value, Label = a.Title, Data = a.Value, Note = a.Note, Code = a.Code, Other = a.Other, Sort = a.Sort, ExpandedIcon = "", CollapsedIcon = "", ChildrenCount = _dictionary.GetAll().Where(r => r.ParentID == a.Id).Count() }).ToList(); return(new ListResultDto <GetDictionaryOutput>(data)); }
/// <summary> /// 转换为字典实体 /// </summary> /// <param name="dto">字典数据传输对象</param> public static Dictionary ToEntity(this DictionaryDto dto) { if (dto == null) { return(new Dictionary()); } return(new Dictionary(dto.Id.ToGuid(), dto.Id, 1) { Code = dto.Code, Text = dto.Text, PinYin = dto.PinYin, ParentId = dto.ParentId.ToGuidOrNull(), Enabled = dto.Enabled.SafeValue(), SortId = dto.SortId, Note = dto.Note, CreationTime = dto.CreationTime, CreatorId = dto.CreatorId, LastModificationTime = dto.LastModificationTime, LastModifierId = dto.LastModifierId, TenantId = dto.TenantId, IsDeleted = dto.IsDeleted.SafeValue(), Version = dto.Version, }); }
public ActionResult EditDic(DictionaryDto dto) { OperationResult result = CommonContract.EditDictionarys(dto); return(Json(result.ToAjaxResult())); }
public ActionResult EditDic(DictionaryDto dto) { OperationResult result = CommonContract.EditDictionarys(dto); return Json(result.ToAjaxResult()); }
private async Task LocalizeItem(DictionaryDto dic) { dic.Name = await _langResourceSingleQuery.Execute(dic.Name, Thread.CurrentThread.CurrentUICulture.IetfLanguageTag); }