예제 #1
0
        //возвращает роль пользователя
        public override string[] GetRolesForUser(string login)
        {
            string[] role = new string[] { };
            using (EntityDataModel db = new EntityDataModel())
            {
                try
                {
                    // Получаем пользователя
                    tbl_1_User user = (from u in db.tbl_1_User
                                       where u.Login == login
                                       select u).FirstOrDefault();
                    if (user != null)
                    {
                        // получаем роль
                        tbl_2_Roles userRole = db.tbl_2_Roles.Find(user.RoleId);

                        if (userRole != null)
                        {
                            role = new string[] { userRole.RoleName };
                        }
                    }
                }
                catch
                {
                    role = new string[] { };
                }
            }
            return(role);
        }
        public void Initialize()
        {
            context = new EntityDataModel();

            DatabaseFiller.ClearDatabase(context);
            DatabaseFiller.FillWithData(context);
        }
 public void Initialize()
 {
     context    = new EntityDataModel();
     repository = new EFAllergenRepository(context);
     DatabaseFiller.ClearDatabase(context);
     DatabaseFiller.FillWithData(context);
 }
예제 #4
0
        /// <summary>
        /// Creates an <see cref="XDocument"/> containing the Metadata XML document for the Entity Data Model.
        /// </summary>
        /// <param name="entityDataModel">The Entity Data Model to include the Metadata for.</param>
        /// <param name="odataServiceOptions">The <see cref="ODataServiceOptions"/> for the service.</param>
        /// <returns>An <see cref="XDocument"/> containing the Metadata XML document for the Entity Data Model.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="entityDataModel"/> or <paramref name="odataServiceOptions"/> is null.</exception>
        public static XDocument Create(EntityDataModel entityDataModel, ODataServiceOptions odataServiceOptions)
        {
            if (entityDataModel is null)
            {
                throw new ArgumentNullException(nameof(entityDataModel));
            }

            if (odataServiceOptions is null)
            {
                throw new ArgumentNullException(nameof(odataServiceOptions));
            }

            var document = new XDocument(
                new XDeclaration("1.0", "utf-8", null),
                new XElement(
                    s_edmxNs + "Edmx",
                    new XAttribute(XNamespace.Xmlns + "edmx", s_edmxNs),
                    new XAttribute("Version", odataServiceOptions.MaxVersion),
                    new XElement(
                        s_edmxNs + "DataServices",
                        new XElement(
                            s_edmNs + "Schema",
                            new XAttribute("xmlns", s_edmNs),
                            new XAttribute("Namespace", entityDataModel.EntitySets.First().Value.EdmType.ClrType.Namespace),
                            GetEnumTypes(entityDataModel),
                            GetComplexTypes(entityDataModel),
                            GetEntityTypes(entityDataModel),
                            GetFunctions(),
                            GetActions(),
                            GetEntityContainer(entityDataModel),
                            GetAnnotations(entityDataModel, odataServiceOptions)))));

            return(document);
        }
 public static void Merge()
 {
     using (var context = new EntityDataModel())
     {
         context.Merge();
     }
 }
예제 #6
0
        private static IEnumerable <XElement> GetComplexTypes(EntityDataModel entityDataModel)
        {
            // Any types used in the model which aren't Entity Sets.
            IEnumerable <EdmComplexType> complexCollectionTypes = entityDataModel.EntitySets.Values
                                                                  .SelectMany(t => t.EdmType.Properties)
                                                                  .Select(p => p.PropertyType)
                                                                  .OfType <EdmCollectionType>()
                                                                  .Select(t => t.ContainedType)
                                                                  .OfType <EdmComplexType>();

            IEnumerable <XElement> complexTypes = entityDataModel.EntitySets.Values
                                                  .SelectMany(t => t.EdmType.Properties)
                                                  .Select(p => p.PropertyType)
                                                  .OfType <EdmComplexType>()
                                                  .Concat(complexCollectionTypes)
                                                  .Where(t => !entityDataModel.IsEntitySet(t))
                                                  .Distinct()
                                                  .Select(t =>
            {
                var element = new XElement(
                    s_edmNs + "ComplexType",
                    new XAttribute("Name", t.Name),
                    GetProperties(t.Properties));

                if (t.BaseType != null)
                {
                    element.Add(new XAttribute("BaseType", t.BaseType.FullName));
                }

                return(element);
            });

            return(complexTypes);
        }
예제 #7
0
        public static int Create(EntityDataModel data, RequestProfile requestProfile)
        {
            var sql   = Save(data, "Create", requestProfile);
            var newId = DBDML.RunScalarSQL("Entity.Insert", sql, DataStoreKey);

            return(Convert.ToInt32(newId));
        }
예제 #8
0
        protected override DataTable UpdateData()
        {
            var UpdatedData = new DataTable();
            var data        = new EntityDataModel();

            UpdatedData = TaskTimeTracker.Components.Module.ApplicationDevelopment.EntityDataManager.Search(data, SessionVariables.RequestProfile).Clone();
            for (var i = 0; i < SelectedData.Rows.Count; i++)
            {
                data.EntityId =
                    Convert.ToInt32(SelectedData.Rows[i][EntityDataModel.DataColumns.EntityId].ToString());
                data.Name        = SelectedData.Rows[i][StandardDataModel.StandardDataColumns.Name].ToString();
                data.Description =
                    !string.IsNullOrEmpty(CheckAndGetRepeaterTextBoxValue(StandardDataModel.StandardDataColumns.Description))
                                        ? CheckAndGetRepeaterTextBoxValue(StandardDataModel.StandardDataColumns.Description)
                                        : SelectedData.Rows[i][StandardDataModel.StandardDataColumns.Description].ToString();

                data.SortOrder =
                    !string.IsNullOrEmpty(CheckAndGetRepeaterTextBoxValue(StandardDataModel.StandardDataColumns.SortOrder))
                                        ? int.Parse(CheckAndGetRepeaterTextBoxValue(StandardDataModel.StandardDataColumns.SortOrder).ToString())
                                        : int.Parse(SelectedData.Rows[i][StandardDataModel.StandardDataColumns.SortOrder].ToString());

                TaskTimeTracker.Components.Module.ApplicationDevelopment.EntityDataManager.Update(data, SessionVariables.RequestProfile);
                data          = new EntityDataModel();
                data.EntityId = Convert.ToInt32(SelectedData.Rows[i][EntityDataModel.DataColumns.EntityId].ToString());
                var dt = TaskTimeTracker.Components.Module.ApplicationDevelopment.EntityDataManager.Search(data, SessionVariables.RequestProfile);

                if (dt.Rows.Count == 1)
                {
                    UpdatedData.ImportRow(dt.Rows[0]);
                }
            }
            return(UpdatedData);
        }
예제 #9
0
        public static string Save(EntityDataModel data, string action, RequestProfile requestProfile)
        {
            var sql = "EXEC ";

            switch (action)
            {
            case "Create":
                sql += "dbo.EntityInsert  " +
                       " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) +
                       ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, requestProfile.ApplicationId);
                break;

            case "Update":
                sql += "dbo.EntityUpdate  " +
                       " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId);
                break;

            default:
                break;
            }
            sql = sql + ", " + ToSQLParameter(data, EntityDataModel.DataColumns.EntityId) +
                  ", " + ToSQLParameter(data, StandardDataModel.StandardDataColumns.Name) +
                  ", " + ToSQLParameter(data, StandardDataModel.StandardDataColumns.Description) +
                  ", " + ToSQLParameter(data, StandardDataModel.StandardDataColumns.SortOrder);

            return(sql);
        }
        public static void ByAddWithNoDetect(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                context.Configuration.AutoDetectChangesEnabled = false;

                entities.ForEach(entity => context.Orders.Add(entity));

                context.Configuration.AutoDetectChangesEnabled = true;

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("NoDetect({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
예제 #11
0
        //показывает, связан ли пользователь с данной ролью
        public override bool IsUserInRole(string username, string roleName)
        {
            bool outputResult = false;

            // Находим пользователя
            using (EntityDataModel db = new EntityDataModel())
            {
                try
                {
                    // Получаем пользователя
                    tbl_1_User user = (from u in db.tbl_1_User
                                       where u.Login == username
                                       select u).FirstOrDefault();
                    if (user != null)
                    {
                        // получаем роль
                        tbl_2_Roles userRole = db.tbl_2_Roles.Find(user.RoleId);

                        //сравниваем
                        if (userRole != null && userRole.RoleName == roleName)
                        {
                            outputResult = true;
                        }
                    }
                }
                catch
                {
                    outputResult = false;
                }
            }
            return(outputResult);
        }
        public static void ByMerge(int count)
        {
            DatabaseOps.ClearPrimaryTable();
            DatabaseOps.CreateTempTable();

            Insert.BySqlBulkCopy(count, false);

            using (var context = new EntityDataModel())
            {
                var entities = context.Orders.ToList();

                entities.ForEach(entity => entity.Date = DateTime.Now.AddYears(100));

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                Insert.BulkCopy(entities, "Order_TEMP");

                DatabaseOps.Merge();

                stopwatch.Stop();

                Console.WriteLine("MERGE({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }

            DatabaseOps.DropTempTable();
        }
예제 #13
0
        public static DataSet GetChildren(EntityDataModel data, RequestProfile requestProfile)
        {
            var sql = "EXEC dbo.EntityChildrenGet" +
                      " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) +
                      ", " + ToSQLParameter(data, EntityDataModel.DataColumns.EntityId);
            var oDT = new Framework.Components.DataAccess.DBDataSet("Get Children", sql, DataStoreKey);

            return(oDT.DBDataset);
        }
 public void UpdateResults()
 {
     using (EntityDataModel be = new EntityDataModel())
     {
         // Just update existing list, instead of creating a new one.
        Results.Clear();
        be.tePersons.Select(x => new PersonName { Name = x.FirstName }).ToList().ForEach(item => Results.Add(item);
     }
 }
예제 #15
0
        protected override DataTable GetEntityData(int?entityKey)
        {
            var functionalityActiveStatusdata = new EntityDataModel();

            functionalityActiveStatusdata.EntityId = entityKey;
            var results = TaskTimeTracker.Components.Module.ApplicationDevelopment.EntityDataManager.Search(functionalityActiveStatusdata, SessionVariables.RequestProfile);

            return(results);
        }
예제 #16
0
        private System.Data.DataTable GetData()
        {
            // TODO: on all export pages
            var data = new EntityDataModel();

            var dt = TaskTimeTracker.Components.Module.ApplicationDevelopment.EntityDataManager.Search(data, SessionVariables.RequestProfile);

            return(dt);
        }
예제 #17
0
        protected override void Update(Dictionary <string, string> values)
        {
            var data = new EntityDataModel();

            // copies properties from values dictionary object to data object
            PropertyMapper.CopyProperties(data, values);

            TaskTimeTracker.Components.Module.ApplicationDevelopment.EntityDataManager.Update(data, SessionVariables.RequestProfile);
            base.Update(values);
        }
        public void CollectionNamesCaseInsensitiveByDefault_ResolveCollectionVaryingCollectionNameCasing()
        {
            var entityDataModelBuilder = new EntityDataModelBuilder(StringComparer.OrdinalIgnoreCase);

            entityDataModelBuilder.RegisterEntitySet <Category>("Categories", x => x.Name);

            EntityDataModel entityDataModel = entityDataModelBuilder.BuildModel();

            Assert.Same(entityDataModel.EntitySets["categories"], entityDataModel.EntitySets["Categories"]);
        }
예제 #19
0
        public MainWindow()
        {
            context = new EntityDataModel();
            //DatabaseFiller.ClearDatabase(context);
            //DatabaseFiller.FillWithData(context);

            InitializeComponent();

            _viewModel  = new MainWindowViewModel();
            DataContext = _viewModel;
        }
예제 #20
0
        public static bool DoesExist(EntityDataModel data, RequestProfile requestProfile)
        {
            var doesExistRequest = new EntityDataModel();

            doesExistRequest.ApplicationId = data.ApplicationId;
            doesExistRequest.Name          = data.Name;

            var list = GetEntityDetails(doesExistRequest, requestProfile, 0);

            return(list.Count > 0);
        }
        static DatabaseOps()
        {
            using (var context = new EntityDataModel())
            {
                var connection = context.Database.Connection;

                Server server = new Server(new ServerConnection(new SqlConnection(connection.ConnectionString)));

                Database = server.Databases[connection.Database];
            }
        }
예제 #22
0
        public override void CreateRole(string roleName)
        {
            tbl_2_Roles newRole = new tbl_2_Roles()
            {
                RoleName = roleName
            };
            EntityDataModel db = new EntityDataModel();

            db.tbl_2_Roles.Add(newRole);
            db.SaveChanges();
        }
        public EntityDataModelTests()
        {
            EntityDataModelBuilder entityDataModelBuilder = new EntityDataModelBuilder(StringComparer.OrdinalIgnoreCase)
                                                            .RegisterEntitySet <Category>("Categories", x => x.Name, Capabilities.Insertable | Capabilities.Updatable | Capabilities.Deletable)
                                                            .RegisterEntitySet <Customer>("Customers", x => x.CompanyName, Capabilities.Updatable)
                                                            .RegisterEntitySet <Employee>("Employees", x => x.Id)
                                                            .RegisterEntitySet <Manager>("Managers", x => x.Id)
                                                            .RegisterEntitySet <Order>("Orders", x => x.OrderId, Capabilities.Insertable | Capabilities.Updatable)
                                                            .RegisterEntitySet <Product>("Products", x => x.ProductId, Capabilities.Insertable | Capabilities.Updatable);

            _entityDataModel = entityDataModelBuilder.BuildModel();
        }
            public WhenCalling_BuildModelWith_Models_AndCustomEntitySetName()
            {
                var entityDataModelBuilder = new EntityDataModelBuilder(StringComparer.OrdinalIgnoreCase);

                entityDataModelBuilder.RegisterEntitySet <Category>("Categories", x => x.Name, Capabilities.Insertable | Capabilities.Updatable | Capabilities.Deletable);
                entityDataModelBuilder.RegisterEntitySet <Customer>("Customers", x => x.CompanyName, Capabilities.Updatable);
                entityDataModelBuilder.RegisterEntitySet <Employee>("Employees", x => x.Id);
                entityDataModelBuilder.RegisterEntitySet <Manager>("Managers", x => x.Id);
                entityDataModelBuilder.RegisterEntitySet <Order>("Orders", x => x.OrderId, Capabilities.Insertable | Capabilities.Updatable);
                entityDataModelBuilder.RegisterEntitySet <Product>("Products", x => x.ProductId, Capabilities.Insertable | Capabilities.Updatable);

                this.entityDataModel = entityDataModelBuilder.BuildModel();
            }
            public WhenCalling_BuildModelWith_Models_AndTypeNameForEntitySetName()
            {
                var entityDataModelBuilder = new EntityDataModelBuilder(StringComparer.OrdinalIgnoreCase);

                entityDataModelBuilder.RegisterEntitySet <Category>(x => x.Name);
                entityDataModelBuilder.RegisterEntitySet <Customer>(x => x.CompanyName);
                entityDataModelBuilder.RegisterEntitySet <Employee>(x => x.Id);
                entityDataModelBuilder.RegisterEntitySet <Manager>(x => x.Id);
                entityDataModelBuilder.RegisterEntitySet <Order>(x => x.OrderId);
                entityDataModelBuilder.RegisterEntitySet <Product>(x => x.ProductId);

                this.entityDataModel = entityDataModelBuilder.BuildModel();
            }
예제 #26
0
        private static XElement GetEntityContainer(EntityDataModel entityDataModel)
        {
            var entityContainer = new XElement(
                s_edmNs + "EntityContainer",
                new XAttribute("Name", "DefaultContainer"),
                entityDataModel.EntitySets.Select(
                    kvp => new XElement(
                        s_edmNs + "EntitySet",
                        new XAttribute("Name", kvp.Key),
                        new XAttribute("EntityType", kvp.Value.EdmType.ClrType.FullName),
                        new XElement(
                            s_edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Core.V1.ResourcePath"),
                            new XAttribute("String", kvp.Key)),
                        new XElement(
                            s_edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Capabilities.V1.InsertRestrictions"),
                            new XElement(
                                s_edmNs + "Record",
                                new XElement(
                                    s_edmNs + "PropertyValue",
                                    new XAttribute("Property", "Insertable"),
#pragma warning disable CA1308 // Normalize strings to uppercase
                                    new XAttribute("Bool", ((kvp.Value.Capabilities & Capabilities.Insertable) == Capabilities.Insertable).ToString(CultureInfo.InvariantCulture).ToLowerInvariant())))),
#pragma warning restore CA1308 // Normalize strings to uppercase
                        new XElement(
                            s_edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Capabilities.V1.UpdateRestrictions"),
                            new XElement(
                                s_edmNs + "Record",
                                new XElement(
                                    s_edmNs + "PropertyValue",
                                    new XAttribute("Property", "Updatable"),
#pragma warning disable CA1308 // Normalize strings to uppercase
                                    new XAttribute("Bool", ((kvp.Value.Capabilities & Capabilities.Updatable) == Capabilities.Updatable).ToString(CultureInfo.InvariantCulture).ToLowerInvariant())))),
#pragma warning restore CA1308 // Normalize strings to uppercase
                        new XElement(
                            s_edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Capabilities.V1.DeleteRestrictions"),
                            new XElement(
                                s_edmNs + "Record",
                                new XElement(
                                    s_edmNs + "PropertyValue",
                                    new XAttribute("Property", "Deletable"),
#pragma warning disable CA1308 // Normalize strings to uppercase
                                    new XAttribute("Bool", ((kvp.Value.Capabilities & Capabilities.Deletable) == Capabilities.Deletable).ToString(CultureInfo.InvariantCulture).ToLowerInvariant())))))));

#pragma warning restore CA1308 // Normalize strings to uppercase

            return(entityContainer);
        }
예제 #27
0
 public static void ClearDatabase(EntityDataModel model)
 {
     model.Allergens.RemoveRange(model.Allergens);
     model.Customers.RemoveRange(model.Customers);
     model.CustomizedProducts.RemoveRange(model.CustomizedProducts);
     model.Orders.RemoveRange(model.Orders);
     model.Employees.RemoveRange(model.Employees);
     model.EmployeeCategories.RemoveRange(model.EmployeeCategories);
     model.TimeIntervals.RemoveRange(model.TimeIntervals);
     model.Toppings.RemoveRange(model.Toppings);
     model.ToppingCategories.RemoveRange(model.ToppingCategories);
     model.Products.RemoveRange(model.Products);
     model.ProductCategories.RemoveRange(model.ProductCategories);
     model.SaveChanges();
 }
예제 #28
0
        public static void Delete(EntityDataModel data, RequestProfile requestProfile)
        {
            const string sql = @"dbo.EntityDelete ";

            var parameters =
                new
            {
                AuditId    = requestProfile.AuditId
                , EntityId = data.EntityId
            };

            using (var dataAccess = new DataAccessBase(DataStoreKey))
            {
                dataAccess.Connection.Execute(sql, parameters, commandType: CommandType.StoredProcedure);
            }
        }
예제 #29
0
        private static XElement GetEntityContainer(EntityDataModel entityDataModel)
        {
            var entityContainer = new XElement(
                edmNs + "EntityContainer",
                new XAttribute(
                    "Name", "DefaultContainer"),
                entityDataModel.EntitySets.Select(
                    kvp => new XElement(
                        edmNs + "EntitySet",
                        new XAttribute("Name", kvp.Key),
                        new XAttribute("EntityType", kvp.Value.EdmType.ClrType.FullName),
                        new XElement(
                            edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Core.V1.ResourcePath"),
                            new XAttribute("String", kvp.Key)),
                        new XElement(
                            edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Capabilities.V1.InsertRestrictions"),
                            new XElement(
                                edmNs + "Record",
                                new XElement(
                                    edmNs + "PropertyValue",
                                    new XAttribute("Property", "Insertable"),
                                    new XAttribute("Bool", ((kvp.Value.Capabilities & Capabilities.Insertable) == Capabilities.Insertable).ToString())))),
                        new XElement(
                            edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Capabilities.V1.UpdateRestrictions"),
                            new XElement(
                                edmNs + "Record",
                                new XElement(
                                    edmNs + "PropertyValue",
                                    new XAttribute("Property", "Updatable"),
                                    new XAttribute("Bool", ((kvp.Value.Capabilities & Capabilities.Updatable) == Capabilities.Updatable).ToString())))),
                        new XElement(
                            edmNs + "Annotation",
                            new XAttribute("Term", "Org.OData.Capabilities.V1.DeleteRestrictions"),
                            new XElement(
                                edmNs + "Record",
                                new XElement(
                                    edmNs + "PropertyValue",
                                    new XAttribute("Property", "Deletable"),
                                    new XAttribute("Bool", ((kvp.Value.Capabilities & Capabilities.Deletable) == Capabilities.Deletable).ToString())))))));

            return(entityContainer);
        }
예제 #30
0
        public static bool IsDeletable(EntityDataModel data, RequestProfile requestProfile)
        {
            var isDeletable = true;
            var ds          = GetChildren(data, requestProfile);

            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataTable dt in ds.Tables)
                {
                    if (dt.Rows.Count > 0)
                    {
                        isDeletable = false;
                        break;
                    }
                }
            }
            return(isDeletable);
        }