private string GetDataContractPropertiesFormatted(IDTOModel 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);
        }
예제 #2
0
 internal bool Equals(IDTOModel dtoModel)
 {
     if (dtoModel.Equals(DbUserObject))
     {
         return(true);
     }
     return(false);
 }
예제 #3
0
        private static void SendPost(HttpClient Client, string ControllerUrl, IDTOModel DtoModel)
        {
            HttpResponseMessage response = Client.PostAsJsonAsync(ControllerUrl, DtoModel).Result;

            string msg = response.IsSuccessStatusCode ?
                         "Success!" :
                         string.Format("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);

            Console.WriteLine(msg);
        }
        private IStereotype GetDataContractStereotype(IDTOModel dto)
        {
            IStereotype stereotype;

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

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

            return(null);
        }
예제 #5
0
        /// <summary>
        /// Добавляет сущность в базу данных на основе параметров входного IDTOModel.
        /// </summary>
        ///
        /// <param name="inputDTO"> Объект IDTOModel, параметры которого
        ///                         будут основой для добавляемого объекта.
        ///                         Тип класса влияет на тип сохраняемой сущности. </param>
        /// <remarks>
        /// Тип входного inputDTO влияет на тип сохраняемой сущности. </remarks>
        ///
        /// <returns> Task(bool), Result которого true, если операция добавления была успешно выполнена.
        /// Иначе, если тип класса входного IDTOModel не поддерживается в методе,
        /// сущность не будет сохранена и Result будет равен false.
        /// </returns>
        public async Task <bool> AddEntityToDb(IDTOModel inputDTO)
        {
            if (inputDTO.GetType() == typeof(DTONews))
            {
                DbNews news = inputDTO.DbObject as DbNews;

                _context.News.Add(news);
                await _context.SaveChangesAsync();
            }
            else if (inputDTO.GetType() == typeof(DTOUser))
            {
                DbUser user = inputDTO.DbObject as DbUser;

                _context.Users.Add(user);
                await _context.SaveChangesAsync();
            }
            else
            {
                return(false);
            }

            return(true);
        }
 public string PropertyAttributes(IDTOModel dto, IDTOField field)
 {
     return("[DataMember]");
 }
 public string ClasssAttributes(IDTOModel dto)
 {
     return($"[DataContract{ GetDataContractPropertiesFormatted(dto) }]");
 }
예제 #8
0
 public string ClasssAttributes(IDTOModel dto)
 {
     return("[DataContract]");
 }