Created
March 28, 2015 20:27
-
-
Save ichensky/ae0d0f181ec9d3a049f2 to your computer and use it in GitHub Desktop.
Questionnarie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication3 | |
{ | |
class Category | |
{ | |
public string Id; | |
public int Type; // 0 - cars; 1 - films | |
public string CategoryId; | |
public List<Category> ListCategories = new List<Category>(); | |
public List<ObjType> ListObjTypes = new List<ObjType>(); | |
} | |
class ObjType | |
{ | |
public string Name; | |
public bool IsDelete; | |
public string Id; // questionnaire; catalog | |
public string CategoryId; | |
public List<Obj> ListObjs = new List<Obj>(); | |
public List<PropType> ListPropTypes = new List<PropType>(); | |
} | |
class PropType | |
{ | |
public int Type; // questionnaire: 0 - date field(DateTime)/many/, 1 - text field(String)/many/, 2 - catalog value(PropId)/many/; catalog: 0 - type, 1 - value(String)/many/ | |
public string Name; | |
public bool IsRequired; | |
public bool IsReadonly; | |
public DateTime DateTimeMinValue; | |
public DateTime DateTimeMaxValue; | |
public string Id; | |
public string ObjTypeId; | |
public string ObjId; // PropType can be an object, for ex. catalog | |
public List<Prop> ListProps = new List<Prop>(); | |
} | |
class Obj | |
{ | |
public string Id; | |
public DateTime CreationDateTime; | |
public string ObjTypeId; | |
public string UserId; // questionnaire: fill in user | |
public List<Prop> ListProps = new List<Prop>(); | |
} | |
class Prop | |
{ | |
public string Id; | |
public DateTime DateTime; | |
public string String; // nvarchar(max) | |
public int Int; | |
public bool Bool; | |
public int Flag; | |
public bool IsDelete; | |
public string ObjPropTypeId; | |
public string ObjId; | |
public string PropId; // questionnaire -> link to item from catalog | |
} | |
class User | |
{ | |
public string Id; | |
public string UserName; | |
public string UserFirstName; | |
public string UserSecondName; | |
public string UserEmail; | |
public int UserPhone; // NULL | |
public List<Obj> ListObjs = new List<Obj>(); | |
} | |
class Program | |
{ | |
enum Categories | |
{ | |
Cars = 0, | |
Films = 1 | |
} | |
#region Props | |
enum Area | |
{ | |
Type | |
} | |
enum QuestionnaireType | |
{ | |
DateTime = 0, | |
String = 1, | |
Catalog | |
} | |
enum Catalog | |
{ | |
Type, | |
Value | |
} | |
#endregion | |
enum CatalogCars | |
{ | |
Color = 0, | |
CarMark = 1 | |
} | |
enum CatalogFilms | |
{ | |
Genre = 0, | |
Style = 1 | |
} | |
static void Main(string[] args) | |
{ | |
var user = new User() { Id = GetId(), UserName = "admin", UserEmail = "admin@some.email", UserFirstName = "Bob", UserSecondName = "Marley", UserPhone = 123 }; | |
var user1 = new User() { Id = GetId(), UserName = "user1", UserEmail = "user1@some.email", UserFirstName = "Bob1", UserSecondName = "Marley1" }; | |
var user2 = new User() { Id = GetId(), UserName = "user2", UserEmail = "user2@some.email", UserFirstName = "Bob2", UserSecondName = "Marley2", UserPhone = 123 }; | |
// Users | |
var users = new List<User>() { user, user1, user2 }; | |
// Categories | |
var catCars = new Category() { Id = GetId(), Type = (int)Categories.Cars }; | |
var catFilms = new Category() { Id = GetId(), Type = (int)Categories.Films }; | |
var cats = new List<Category>() { catCars, catFilms }; | |
// Basic Types | |
var catalogType = new ObjType() { Id = GetId(), Name = "Catalog", CategoryId = catCars.Id }; | |
var catalogTypePropType = new PropType() { Id = GetId(), Name = "type", Type = (int)Catalog.Type, ObjTypeId = catalogType.Id }; | |
var catalogTypePropValue = new PropType() { Id = GetId(), Name = "value", Type = (int)Catalog.Value, ObjTypeId = catalogType.Id }; | |
catalogType.ListPropTypes.AddRange(new List<PropType>() { catalogTypePropType, catalogTypePropValue }); | |
var types = new List<ObjType>() { catalogType }; | |
// Catalogs in Areas | |
var c1 = new Obj() { Id = GetId(), ObjTypeId = catalogType.Id }; | |
var cType1 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropType.Id, Int = (int)CatalogCars.CarMark, ObjId = c1.Id }; | |
var cValue1 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "BMW", ObjId = c1.Id }; | |
var cValue12 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Mercedes", ObjId = c1.Id }; | |
var cValue13 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Lanos", ObjId = c1.Id }; | |
var cValue14 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Ferrari", ObjId = c1.Id }; | |
var cValue15 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Lamborghini", ObjId = c1.Id }; | |
var l = new List<Prop>() { cType1, cValue1, cValue12, cValue13, cValue14, cValue15 }; | |
c1.ListProps.AddRange(l); | |
catalogType.ListObjs.Add(c1); | |
var c2 = new Obj() { Id = GetId(), ObjTypeId = catalogType.Id }; | |
var cType2 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropType.Id, Int = (int)CatalogCars.Color, ObjId = c2.Id }; | |
var cValue2 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Black", ObjId = c2.Id }; | |
var cValue22 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "White", ObjId = c2.Id }; | |
var cValue23 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Green", ObjId = c2.Id }; | |
var cValue24 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Brown", ObjId = c2.Id }; | |
var cValue25 = new Prop() { Id = GetId(), ObjPropTypeId = catalogTypePropValue.Id, String = "Red", ObjId = c2.Id }; | |
var l2 = new List<Prop>() { cType1, cValue1, cValue12, cValue13, cValue14, cValue15 }; | |
c2.ListProps.AddRange(l2); | |
catalogType.ListObjs.Add(c2); | |
// User Types | |
var type1 = new ObjType() { Id = GetId(), Name = "Questionnaire", CategoryId = catCars.Id }; | |
var typeProp1 = new PropType() { Id = GetId(), Name = "date field", Type = (int)QuestionnaireType.DateTime, ObjTypeId = type1.Id }; | |
var typeProp12 = new PropType() { Id = GetId(), Name = "text field", Type = (int)QuestionnaireType.String, ObjTypeId = type1.Id }; | |
var typeProp13 = new PropType() { Id = GetId(), Name = "catalog field", Type = (int)QuestionnaireType.Catalog, ObjTypeId = type1.Id, ObjId = c2.Id }; | |
var typeProp14 = new PropType() { Id = GetId(), Name = "text field", Type = (int)QuestionnaireType.String, ObjTypeId = type1.Id }; | |
var typeProp15 = new PropType() { Id = GetId(), Name = "text field", Type = (int)QuestionnaireType.String, ObjTypeId = type1.Id }; | |
type1.ListPropTypes.AddRange(new List<PropType>() { typeProp1, typeProp12, typeProp13, typeProp14, typeProp15 }); | |
// Objects | |
var questionnaire = new Obj() { Id = GetId(), ObjTypeId = type1.Id, CreationDateTime = DateTime.UtcNow, UserId = user2.Id }; | |
foreach (var item in type1.ListPropTypes) | |
{ | |
var questionnaireProp = new Prop() { Id = GetId(), ObjPropTypeId = item.Id, ObjId = questionnaire.Id }; | |
// just insert user data(here random) | |
switch ((QuestionnaireType)item.Type) | |
{ | |
case QuestionnaireType.DateTime: | |
questionnaireProp.DateTime = DateTime.UtcNow; | |
break; | |
case QuestionnaireType.String: | |
questionnaireProp.String = "abc"; | |
break; | |
case QuestionnaireType.Catalog: | |
questionnaireProp.String = "Selected value"; | |
//questionnaireProp.PropId = | |
break; | |
} | |
questionnaire.ListProps.Add(questionnaireProp); | |
} | |
type1.ListObjs.Add(questionnaire); | |
user2.ListObjs.Add(questionnaire); // If user not created, let's create him | |
} | |
public static string GetId() { return Guid.NewGuid().ToString(); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment