public Task <DataResult <DTOModel> > EditModelAsync(DTOModel modelDTO)
        {
            return(Task.Run(() => {
                var modelRepository = _unitOfWork.GetRepository <Model>();

                var modelEntity = _mapper.Map <Model>(modelDTO);
                var updatedModelDTO = new DTOModel();
                if ((modelRepository.ExistByCondition(x => (x.Name == modelEntity.Name && x.Id == modelEntity.Id))) || (!modelRepository.ExistByCondition(x => x.Name == modelEntity.Name)))
                {
                    var updatedModelEntity = modelRepository.Update(modelEntity);
                    _unitOfWork.SaveChanges();

                    updatedModelDTO = _mapper.Map <DTOModel>(updatedModelEntity);

                    return new DataResult <DTOModel> {
                        Errors = new List <ErrorDescriber>(), Target = updatedModelDTO
                    };
                }
                else
                {
                    return new DataResult <DTOModel> {
                        Errors = new List <ErrorDescriber> {
                            new ErrorDescriber("Existed Model Name")
                        }, Target = updatedModelDTO
                    };
                }
            }));
        }
        private string GetDataContractPropertiesFormatted(DTOModel dto)
        {
            var dataContractStereotype = GetDataContractStereotype(dto);

            if (dataContractStereotype != null)
            {
                var sb = new StringBuilder();

                var @namespace = dataContractStereotype.GetProperty <string>("Namespace");
                if (!string.IsNullOrEmpty(@namespace))
                {
                    sb.Append($@"Namespace=""{ @namespace }""");
                }

                var isReference = dataContractStereotype.GetProperty <bool>("IsReference");
                if (isReference)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(" ");
                    }

                    sb.Append($@"IsReference=""{ isReference }""");
                }

                if (sb.Length > 0)
                {
                    sb.Insert(0, "( ");
                    sb.Append(" )");

                    return(sb.ToString());
                }
            }
            return(string.Empty);
        }
Example #3
0
        public DTOModel ToDTO(Model_ model)
        {
            DTOModel dTOModel = new DTOModel();

            dTOModel.Name    = model.Name;
            dTOModel.BrandID = model.BrandID;
            dTOModel.ID      = model.ID;
            return(dTOModel);
        }
        public string FromBody2([FromBody] DTOModel orderDTO)
        {
            if (orderDTO == null || orderDTO.ID == 0)
            {
                return("解析参数异常");
            }

            return("成功!!" + orderDTO.ID);
        }
        public bool IsMatch()
        {
            if (_template.Model.TypeReference.Element == null)
            {
                return(false);
            }

            if (_template.Model.Properties.Count() != 1)
            {
                return(false);
            }

            var matchingEntities = _metadataManager.Domain(_application).GetClassModels().Where(x => new[]
            {
                $"get{x.Name.ToLower()}",
                $"get{x.Name.ToLower()}byid",
                $"find{x.Name.ToLower()}",
                $"find{x.Name.ToLower()}byid",
                $"lookup{x.Name.ToLower()}",
                $"lookup{x.Name.ToLower()}byid",
            }.Contains(_template.Model.Name.ToLower().RemoveSuffix("query"))).ToList();

            if (matchingEntities.Count() != 1)
            {
                return(false);
            }
            _foundEntity = matchingEntities.Single();

            _dtoToReturn = _metadataManager.Services(_application).GetDTOModels().SingleOrDefault(x => x.Id == _template.Model.TypeReference.Element.Id && x.IsMapped && x.Mapping.ElementId == _foundEntity.Id);
            if (_dtoToReturn == null)
            {
                return(false);
            }

            _idProperty = _template.Model.Properties.FirstOrDefault(p =>
                                                                    string.Equals(p.Name, "id", StringComparison.InvariantCultureIgnoreCase) ||
                                                                    string.Equals(p.Name, $"{_foundEntity.Name}Id", StringComparison.InvariantCultureIgnoreCase));
            if (_idProperty == null)
            {
                return(false);
            }

            var repositoryInterface = _template.GetTypeName(EntityRepositoryInterfaceTemplate.TemplateId, _foundEntity, new TemplateDiscoveryOptions()
            {
                ThrowIfNotFound = false
            });

            if (repositoryInterface == null)
            {
                return(false);
            }
            _repository = new RequiredService(type: repositoryInterface, name: repositoryInterface.Substring(1).ToCamelCase());
            return(true);
        }
Example #6
0
        public List <DTOModel> ConvertAndMergeModel(string filename)
        {
            var location = Directory.GetCurrentDirectory();

            string csv = location + "\\Upload\\" + filename;


            Dictionary <string, List <KeyValuePair <string, string> > > outputDictionary =
                new Dictionary <string, List <KeyValuePair <string, string> > >();

            outputDictionary = BuildModel(outputDictionary, csv);



            List <DTOModel> dtoMdls = new List <DTOModel>();

            // CultureInfo culture = new CultureInfo("fr-FR");

            foreach (var unit in outputDictionary)
            {
                DTOModel dtoMdl = new DTOModel();
                dtoMdl.DateTime = Convert.ToDateTime(unit.Key);
                dtoMdl.child    = new List <ChildClass>();
                foreach (var keyValue in unit.Value)
                {
                    ChildClass child = new ChildClass();
                    child.PropertyName = keyValue.Key;
                    child.Value        = int.Parse(keyValue.Value);
                    dtoMdl.child.Add(child);
                }

                var puranData = Get(dtoMdl.DateTime);
                if (puranData != null)
                {
                    foreach (var child in dtoMdl.child)
                    {
                        puranData.child.Add(child);
                    }
                    UpdateDTO(puranData.DateTime, puranData);
                }
                else
                {
                    _analytics2.InsertOne(dtoMdl);
                }
            }



            return(dtoMdls);
        }
        public Task <DataResult <DTOModel> > GetModelByIdAsync(int id)
        {
            return(Task.Run(() => {
                var modelDTO = new DTOModel();
                var modelRepository = _unitOfWork.GetRepository <Model>();

                var service = modelRepository.GetById(id);
                if (service != null)
                {
                    modelDTO = _mapper.Map <DTOModel>(service);
                }

                return new DataResult <DTOModel> {
                    Errors = new List <ErrorDescriber>(), Target = modelDTO
                };
            }));
        }
        private IStereotype GetDataContractStereotype(DTOModel dto)
        {
            IStereotype stereotype;

            stereotype = dto.GetStereotype("DataContract");
            if (stereotype != null)
            {
                return(stereotype);
            }

            stereotype = dto.GetStereotypeInFolders("DataContract");
            if (stereotype != null)
            {
                return(stereotype);
            }

            return(null);
        }
Example #9
0
        public bool IsMatch()
        {
            if (_template.Model.TypeReference.Element == null || !_template.Model.TypeReference.IsCollection)
            {
                return(false);
            }

            var matchingEntities = _metadataManager.Domain(_application).GetClassModels().Where(x => new[]
            {
                $"get{x.Name.ToPluralName().ToLower()}",
                $"getall{x.Name.ToPluralName().ToLower()}",
                $"find{x.Name.ToPluralName().ToLower()}",
                $"findall{x.Name.ToPluralName().ToLower()}",
                $"lookup{x.Name.ToPluralName().ToLower()}",
                $"lookupall{x.Name.ToPluralName().ToLower()}",
            }.Contains(_template.Model.Name.ToLower().RemoveSuffix("query"))).ToList();

            if (matchingEntities.Count() != 1)
            {
                return(false);
            }
            _foundEntity = matchingEntities.Single();

            _dtoToReturn = _metadataManager.Services(_application).GetDTOModels().SingleOrDefault(x => x.Id == _template.Model.TypeReference.Element.Id && x.IsMapped && x.Mapping.ElementId == _foundEntity.Id);
            if (_dtoToReturn == null)
            {
                return(false);
            }

            var repositoryInterface = _template.GetTypeName(EntityRepositoryInterfaceTemplate.TemplateId, _foundEntity, new TemplateDiscoveryOptions()
            {
                ThrowIfNotFound = false
            });

            if (repositoryInterface == null)
            {
                return(false);
            }
            _repository = new RequiredService(type: repositoryInterface, name: repositoryInterface.Substring(1).ToCamelCase());
            return(true);
        }
        public Task <DataResult <DTOModel> > CreateModelAsync(DTOModel modelDTO)
        {
            return(Task.Run(() => {
                var createdServiceDTO = new DTOModel();

                var modelRepository = _unitOfWork.GetRepository <Model>();
                var modelEntity = _mapper.Map <Model>(modelDTO);

                if (!modelRepository.ExistByCondition(x => x.Name == modelEntity.Name))
                {
                    var createdServiceEntity = modelRepository.Insert(modelEntity);
                    _unitOfWork.SaveChanges();

                    createdServiceDTO = _mapper.Map <DTOModel>(createdServiceEntity);
                }

                return new DataResult <DTOModel> {
                    Errors = new List <ErrorDescriber>(), Target = createdServiceDTO
                };
            }));
        }
Example #11
0
 public void UpdateDTO(DateTime datetime, DTOModel dtoModel) => _analytics2.ReplaceOne(a => a.DateTime == datetime,
                                                                                       dtoModel);
Example #12
0
 public virtual string PropertyAttributes(DTOModel dto, DTOFieldModel field) => null;
Example #13
0
 public virtual string ClassAttributes(DTOModel dto) => null;
 public override string PropertyAttributes(DTOModel dto, DTOFieldModel field)
 {
     return(@"
 [DataMember]");
 }
 public override string ClassAttributes(DTOModel dto)
 {
     return($"[DataContract{ GetDataContractPropertiesFormatted(dto) }]");
 }
Example #16
0
 public async Task <IHttpActionResult> Put([FromBody] DTOModel modelDTO)
 {
     return(await ExecuteServiceReturnDefaultResult(() => _serviceBuilder.Parameter.ModelService.EditModelAsync(modelDTO), false));
 }