Пример #1
0
        public ActionResult AddReply(FormCollection form)
        {
            Admin aInfo = db.Admin.Where(s => s.Id == adminId).FirstOrDefault();
            int id = Convert.ToInt32(form["GroupID"]);
            TitleContent tContent = new TitleContent()
            {
                Content = form["Content"],
                CourseGroupTitleId = id,
                FromId = aInfo.Id,
                FromName = aInfo.UserName,
                FromAccount = aInfo.Account,
                FromDate = DateTime.Now.ToLongDateString()+DateTime.Now.ToShortTimeString()
            };

            ModelHelpers mHelp = new ModelHelpers();

            try
            {
                mHelp.Add<TitleContent>(tContent);
            }
            catch (Exception)
            {
                TempData["msg"] = "回复失败";
                return RedirectToAction("GroupDetail", new { id = id });
            }

            return RedirectToAction("GroupDetail", new { id = id });
        }
Пример #2
0
 public ActionResult Register(StudentInfo userModel)
 {
     userModel.Authority = "0";
     ModelHelpers mHelp = new ModelHelpers();
     mHelp.Add<StudentInfo>(userModel);
     CourseCenter.Common.TakeCookie.SetCookie("userId", userModel.Id.ToString());
     return RedirectToAction("StudentIndex", "Home");
 }
Пример #3
0
 public ActionResult AddNewCourse(Course course)
 {
     string teacherId = TakeCookie.GetCookie("userId");
     course.CourseStatus = 0;
     course.TeacherId = new Guid(teacherId);
     ModelHelpers mHelp = new ModelHelpers();
     mHelp.Add<Course>(course);
     return RedirectToAction("CoursesDetail", new { id = course.Id });
 }
Пример #4
0
 public string DeleteTitle(int id)
 {
     CourseGroupTitle Cgt = new CourseGroupTitle() { Id = id };
     ModelHelpers Mhelp = new ModelHelpers();
     Mhelp.Del<CourseGroupTitle>(Cgt);
     List<CourseGroupTitle> listCgt = db.CourseGroupTitle.OrderBy(g => g.CreatTime).ToList();
     ViewBag.listCgt = listCgt;
     JavaScriptSerializer jss = new JavaScriptSerializer();
     string jsonStr = jss.Serialize(listCgt);
     return jsonStr;
 }
 private void NotExistsTestWithConnection(string username, bool persistSecurityInfo, bool openConnection)
 {
     AssertDoesNotExistWithConnection(
         ModelHelpers.SimpleConnectionStringWithCredentials(
             "IDoNotExist", username, Password, persistSecurityInfo), openConnection);
 }
Пример #6
0
 public Error(ModelHelpers modelHelpers, Event exceptionlessEvent)
 {
     this.modelHelpers = modelHelpers;
     InitializeComponent();
     DataContext = new ErrorModel(exceptionlessEvent);
 }
 private void ExistsTestWithConnection(string username, bool persistSecurityInfo, bool openConnection)
 {
     AssertExistsWithConnection(
         ModelHelpers.SimpleConnectionStringWithCredentials(
             DatabaseName, username, Password, persistSecurityInfo), openConnection);
 }
Пример #8
0
 protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
 {
     base.OnModelCreating(modelBuilder, context);
     ModelHelpers.SimpleTableNames(modelBuilder);
     ModelHelpers.SetPrimaryKeyGeneration(modelBuilder, FbValueGenerationStrategy.IdentityColumn);
 }
Пример #9
0
 protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
 {
     base.OnModelCreating(modelBuilder, context);
     ModelHelpers.SimpleTableNames(modelBuilder, context);
 }
 protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
 {
     base.OnModelCreating(modelBuilder, context);
     ModelHelpers.SetPrimaryKeyGeneration(modelBuilder);
 }
Пример #11
0
        public void ValidEmptyFilters_Test()
        {
            var validationResult = ModelHelpers.ValidateFilters(emptyFilters);

            Assert.Empty(validationResult);
        }
 public FilterSpecificationsTests()
 {
     filterSpecifications = ModelHelpers.GetStreamEventsFilters();
     streamEventsStatuses = ModelHelpers.GetStreamEventStatuses();
 }
 public APIPropertieModel(string columnName, string propertieType)
 {
     this.ColumnName     = columnName;
     this.PropertieType  = propertieType;
     this._propertieName = ModelHelpers.ConvertToPascalCasePattern(ColumnName);
 }
Пример #14
0
        public void ValidMulti2Filters_Test()
        {
            var validationResult = ModelHelpers.ValidateFilters(filterMulti2);

            Assert.Empty(validationResult);
        }
Пример #15
0
        public async Task <IActionResult> TeamEdit(int id, [Bind("Id,TeamName,TeamCode,SubDivisionId, Address,PostCode,Website,About")]
                                                   Team team)
        {
            if (id != team.Id)
            {
                return(NotFound());
            }

            //  once season is in season is in session no changes to team code
            //team.TeamCode = team.TeamCode.ToUpper();

            //  Get Team
            var thisTeam = await _wpbService.GetTeamAsync(id);

            if (thisTeam == null)
            {
                return(NotFound());
            }


            // update the premited value passed in only:
            //  Address,PostCode,Website,About
            thisTeam.About = ModelHelpers.ShortenAndFormatText(team.About, 200);
            //  because we are manually changing the values of about:
            ModelState.Remove("About");
            thisTeam.Address  = team.Address;
            thisTeam.PostCode = team.PostCode;
            thisTeam.Website  = team.Website;


            if (!ModelState.IsValid)
            {
                var divisionList = await _wpbService.GetSubDivisionDropListAsync();

                ViewData["SubDivision"] = new SelectList(divisionList, "Id", "SubDivisionTitle");
                return(View(team));
            }

            //  once season is in season is in session no changes to team code

            /*var subDivCodeExist = _wpbService.TeamCodeExist(team.TeamCode);
             * if (subDivCodeExist)
             * {
             *  var divisionList = await _wpbService.GetSubDivisionDropListAsync();
             *  ViewData["SubDivision"] = new SelectList(divisionList, "Id", "SubDivisionTitle");
             *  ModelState.AddModelError("", "$Team code: {team.TeamCode} is already in use.");
             *  return View(team);
             * }*/

            var teamCodeSanityCheck = await _wpbService.GetTeamAsync(id);

            if (teamCodeSanityCheck != null)
            {
                // no changes to team code
                if (team.TeamCode != teamCodeSanityCheck.TeamCode)
                {
                    var divisionList = await _wpbService.GetSubDivisionDropListAsync();

                    ViewData["SubDivision"] = new SelectList(divisionList, "Id", "SubDivisionTitle");
                    ModelState.AddModelError("", "Changes to team code not allow while in session!");
                    return(View(team));
                }
            }
            else
            {
                return(NotFound());
            }

            var editSuccess = await _wpbService.UpdateTeamAsync(thisTeam);

            if (editSuccess)
            {
                return(RedirectToAction(nameof(TeamsAll)));
            }

            return(NotFound());
        }
Пример #16
0
        public void ValidLimitFilters_Test()
        {
            var validationResult = ModelHelpers.ValidateFilters(filterLimit);

            Assert.Empty(validationResult);
        }
Пример #17
0
        public void ValidStatusFilters_Test()
        {
            var validationResult = ModelHelpers.ValidateFilters(filterStatuses);

            Assert.Empty(validationResult);
        }
Пример #18
0
        public void ValidMachineIdFilters_Test()
        {
            var validationResult = ModelHelpers.ValidateFilters(filterMachineId);

            Assert.Empty(validationResult);
        }
Пример #19
0
 public BlockPropertieModel(Block block)
 {
     BlockId   = block.Id;
     BlockName = ModelHelpers.ConvertToPrivateVariablePattern(block.Name);
 }
Пример #20
0
        public ActionResult GetPersonalInfo(Admin adminInfo)
        {
            //数据库帮助类
               ModelHelpers modelHelp = new ModelHelpers();
            //获取用户(教师)cookie,cookie存储是ID
            try
            {
                string adminId = TakeCookie.GetCookie("userId");
                adminInfo.Id =new Guid( adminId);
                adminInfo.Pwd = adminInfo.Pwd.Trim();
                if (string.IsNullOrEmpty(adminInfo.Pwd) || adminInfo.Pwd == "不修改就不需要输入")
                {
                    modelHelp.Modify<Admin>(adminInfo, new string[] { "Id", "Account", "UserName", "Sex" });
                    TempData["res"] = "修改成功";
                    return RedirectToAction("GetPersonalInfo");
                }
                modelHelp.Modify<Admin>(adminInfo, new string[] { "Id", "Account", "UserName", "Pwd", "Sex" });
                TempData["res"] = "修改成功";
            }
            catch (Exception)
            {
                TempData["res"] = "<font color='red'>修改失败,请点解cancel或刷新 后 重新输入!<font/>";
            }

            return RedirectToAction("GetPersonalInfo");
        }
Пример #21
0
 protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
 {
     base.OnModelCreating(modelBuilder, context);
     ModelHelpers.SetStringLengths(modelBuilder);
 }
        public static void Generate(Type arrayType, string completePath, bool clear, bool appendInFile)
        {
            Type   elementType     = arrayType.GetElementType();
            string elementFullName = elementType.GetPrettyFullName();

            StreamWriter writer = GetFileStream(completePath);

            bool success = true;

            if (!appendInFile)
            {
                writer.WriteLine("// THIS CODE IS GENERATED");
                writer.WriteLine("// DO NOT MODIFY IT");
                writer.WriteLine();
                writer.WriteLine("using System;");
                writer.WriteLine("using System.Collections.Generic;");
            }

            writer.WriteLine();
            writer.WriteLine("public static class " + NetSerializationCodeGenUtility.GetSerializerNameFromType(arrayType));
            writer.WriteLine("{");
            writer.WriteLine("    public static int GetSerializedBitSize(ref " + elementFullName + "[] obj)");
            writer.WriteLine("    {");

            if (clear)
            {
                writer.WriteLine("        return 0;");
            }
            else
            {
                writer.WriteLine("        if (obj == null)");
                writer.WriteLine("            return 1;");
                writer.WriteLine("        int result = 1 + sizeof(Int32) * 8;");
                writer.WriteLine("        for (int i = 0; i < obj.Length; i++)");
                writer.WriteLine("        {");
                writer.WriteLine("            " + ModelHelpers.GetSerializerFieldLine_GetNetBitSize(elementType, "[i]"));
                writer.WriteLine("        }");
                writer.WriteLine("        return result;");
            }

            writer.WriteLine("    }");

            writer.WriteLine();

            writer.WriteLine("    public static void Serialize(ref " + elementFullName + "[] obj, BitStreamWriter writer)");
            writer.WriteLine("    {");
            if (!clear)
            {
                writer.WriteLine("        if (obj == null)");
                writer.WriteLine("        {");
                writer.WriteLine("            writer.WriteBit(false);");
                writer.WriteLine("            return;");
                writer.WriteLine("        }");
                writer.WriteLine("        writer.WriteBit(true);");
                writer.WriteLine("        writer.WriteInt32(obj.Length);");
                writer.WriteLine("        for (int i = 0; i < obj.Length; i++)");
                writer.WriteLine("        {");
                writer.WriteLine("            " + ModelHelpers.GetSerializerFieldLine_Serialize(elementType, "[i]"));
                writer.WriteLine("        }");
            }
            writer.WriteLine("    }");

            writer.WriteLine();

            writer.WriteLine("    public static void Deserialize(ref " + elementFullName + "[] obj, BitStreamReader reader)");
            writer.WriteLine("    {");
            if (!clear)
            {
                writer.WriteLine("        if (reader.ReadBit() == false)");
                writer.WriteLine("        {");
                writer.WriteLine("            obj = null;");
                writer.WriteLine("            return;");
                writer.WriteLine("        }");
                writer.WriteLine("        obj = new " + elementFullName + "[reader.ReadInt32()];");
                writer.WriteLine("        for (int i = 0; i < obj.Length; i++)");
                writer.WriteLine("        {");
                writer.WriteLine("            " + ModelHelpers.GetSerializerFieldLine_Deserialize(elementType, "[i]"));
                writer.WriteLine("        }");
            }
            writer.WriteLine("    }");

            writer.WriteLine("}");


            if (!success)
            {
                Debug.LogWarning("Error in code generation for type: " + elementType);
            }
        }
Пример #23
0
        public StoredProceduresTestFixture()
        {
            using (var masterConnection = new SqlConnection(ModelHelpers.SimpleConnectionString("master")))
            {
                masterConnection.Open();

                var databaseName         = "IceAndFireContext2";
                var databaseExistsScript = string.Format(
                    "SELECT COUNT(*) FROM sys.databases where name = '{0}'", databaseName);

                var databaseExists = (int)new SqlCommand(databaseExistsScript, masterConnection).ExecuteScalar() == 1;
                if (databaseExists)
                {
                    var dropDatabaseScript = string.Format("drop database {0}", databaseName);
                    new SqlCommand(dropDatabaseScript, masterConnection).ExecuteNonQuery();
                }

                var createDatabaseScript = string.Format("create database {0}", databaseName);


//                var createDatabaseScript = string.Format(
//                    @"if exists(select * from sys.databases where name = '{0}')
//drop database {0}
//create database {0}", "IceAndFireContext2");



                new SqlCommand(createDatabaseScript, masterConnection).ExecuteNonQuery();
            }

            var storeConnectionString = ModelHelpers.SimpleConnectionString("IceAndFireContext2");

            using (var connection = new SqlConnection(storeConnectionString))
            {
                connection.Open();

                //string partitionSchemeStatement = SqlAzureTestHelpers.IsSqlAzure(storeConnectionString) ? "" : " ON [PRIMARY]";

                new SqlCommand(
                    @"CREATE TABLE [dbo].[Lands](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[LocationOnMap] [geography] NULL,
 CONSTRAINT [PK_dbo.Lands] PRIMARY KEY CLUSTERED ([Id] ASC))", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE TABLE [dbo].[Houses](
	[Id] [int] NOT NULL,
	[Name] [nvarchar](max) NULL,
	[Words] [nvarchar](max) NULL,
	[Sigil] [geometry] NULL,
 CONSTRAINT [PK_dbo.Houses] PRIMARY KEY CLUSTERED ([Id] ASC))", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE TABLE [dbo].[Creatures](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[Size] [int] NOT NULL,
	[PlaceOfBirth] [geography] NULL,
	[IsCarnivore] [bit] NULL,
	[IsDangerous] [bit] NULL,
	[Discriminator] [nvarchar](128) NOT NULL,
	[House_Id] [int] NULL,
 CONSTRAINT [PK_dbo.Creatures] PRIMARY KEY CLUSTERED ([Id] ASC))", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"ALTER TABLE [dbo].[Creatures]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Creatures_dbo.Houses_House_Id] FOREIGN KEY([House_Id])
REFERENCES [dbo].[Houses] ([Id])", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"ALTER TABLE [dbo].[Houses]  WITH CHECK ADD  CONSTRAINT [FK_dbo.Houses_dbo.Lands_Id] FOREIGN KEY([Id])
REFERENCES [dbo].[Lands] ([Id])", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE PROCEDURE [dbo].[GetAnimalsAndHouses] AS 
SELECT * FROM dbo.Creatures AS c WHERE c.Discriminator = 'Animal' 
SELECT * FROM dbo.Houses", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE PROCEDURE [dbo].[GetHousesAndAnimals] AS 
SELECT * FROM dbo.Houses 
SELECT * FROM dbo.Creatures AS c WHERE c.Discriminator = 'Animal'", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE PROCEDURE [dbo].[GetHousesAndHouses] AS 
SELECT * FROM dbo.Houses 
SELECT * FROM dbo.Houses", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE PROCEDURE [dbo].[GetHumansAndAnimals] AS 
SELECT * FROM dbo.Creatures AS c1 WHERE c1.Discriminator = 'Human' 
SELECT * FROM dbo.Creatures AS c2 WHERE c2.Discriminator = 'Animal'", connection).ExecuteNonQuery();

                new SqlCommand(
                    @"CREATE PROCEDURE [dbo].[GetLandsAndCreatures] AS 
SELECT * FROM dbo.Lands  
SELECT * FROM dbo.Creatures", connection).ExecuteNonQuery();
            }
        }
 public ActionResult <IEnumerable <IFilterSpecifications> > GetFilterSpecs()
 {
     return(Ok(ModelHelpers.GetStreamEventsFilters()));
 }
        public static void Generate(Type listType, string completePath, bool clear, bool appendInFile)
        {
            Type   elementType     = listType.GetGenericArguments()[0];
            string elementFullName = elementType.GetPrettyFullName();

            StreamWriter writer = GetFileStream(completePath);

            bool success = true;

            if (!appendInFile)
            {
                writer.WriteLine("// THIS CODE IS GENERATED");
                writer.WriteLine("// DO NOT MODIFY IT");
                writer.WriteLine();
                writer.WriteLine("using System;");
                writer.WriteLine("using System.Collections.Generic;");
            }

            writer.WriteLine();
            writer.WriteLine("public static class " + NetSerializationCodeGenUtility.GetSerializerNameFromType(listType));
            writer.WriteLine("{");
            writer.WriteLine($"    public static int GetSerializedBitSize_Class(List<{elementFullName}> obj)");
            writer.WriteLine("    {");

            if (clear)
            {
                writer.WriteLine("        return 0;");
            }
            else
            {
                writer.WriteLine("        if (obj == null)");
                writer.WriteLine("            return 1;");
                writer.WriteLine("        int result = 1 + sizeof(Int32) * 8;");
                writer.WriteLine("        for (int i = 0; i < obj.Count; i++)");
                writer.WriteLine("        {");
                writer.WriteLine("            var x = obj[i];");
                writer.WriteLine("            " + ModelHelpers.GetSerializerFieldLine_GetNetBitSize(elementType, null, "x"));
                writer.WriteLine("        }");
                writer.WriteLine("        return result;");
            }

            writer.WriteLine("    }");

            writer.WriteLine();

            writer.WriteLine($"    public static void Serialize_Class(List<{elementFullName}> obj, BitStreamWriter writer)");
            writer.WriteLine("    {");
            if (!clear)
            {
                writer.WriteLine("        if (obj == null)");
                writer.WriteLine("        {");
                writer.WriteLine("            writer.WriteBit(false);");
                writer.WriteLine("            return;");
                writer.WriteLine("        }");
                writer.WriteLine("        writer.WriteBit(true);");
                writer.WriteLine("        writer.WriteInt32(obj.Count);");
                writer.WriteLine("        for (int i = 0; i < obj.Count; i++)");
                writer.WriteLine("        {");
                writer.WriteLine("            var x = obj[i];");
                writer.WriteLine("            " + ModelHelpers.GetSerializerFieldLine_Serialize(elementType, null, "x"));
                writer.WriteLine("        }");
            }
            writer.WriteLine("    }");

            writer.WriteLine();

            writer.WriteLine($"    public static List<{elementFullName}> Deserialize_Class(BitStreamReader reader)");
            writer.WriteLine("    {");
            if (!clear)
            {
                writer.WriteLine("        if (reader.ReadBit() == false)");
                writer.WriteLine("        {");
                writer.WriteLine("            return null;");
                writer.WriteLine("        }");
                writer.WriteLine("        int size = reader.ReadInt32();");
                writer.WriteLine($"        List<{elementFullName}> obj = new List<{elementFullName}>(size);");
                writer.WriteLine("        for (int i = 0; i < size; i++)");
                writer.WriteLine("        {");
                writer.WriteLine($"            {elementFullName} x = default;");
                writer.WriteLine("            " + ModelHelpers.GetSerializerFieldLine_Deserialize(elementType, null, "x"));
                writer.WriteLine($"            obj.Add(x);");
                writer.WriteLine("        }");
                writer.WriteLine("        return obj;");
            }
            writer.WriteLine("    }");

            writer.WriteLine("}");


            if (!success)
            {
                Debug.LogWarning("Error in code generation for type: " + elementType);
            }
        }
Пример #26
0
 public void ShouldCorrectlyParseId()
 {
     ModelHelpers.ParseModelUriId("/a/b/c/12345").ShouldBe(12345);
     ModelHelpers.ParseModelUriId("/a/b/c/12345:xyz").ShouldBe(12345);
 }