本文整理汇总了C#中Session.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Create方法的具体用法?C# Session.Create怎么用?C# Session.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.Create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUser
/// <summary>
/// 增加用户
/// </summary>
/// <param name="session">数据库会话</param>
/// <param name="user">用户</param>
/// <param name="currentAccountNo">当前操作者</param>
/// <returns>是否操作成功</returns>
public static bool AddUser(Session session, User user, string currentAccountNo)
{
return session.Create(user) && user.AddNotExistAccount(session, currentAccountNo);
}
示例2: SaveNavigation
private long SaveNavigation(Session session, PriviledgeAttribute priAttr, long parentId, string area, string controller, string action)
{
if (priAttr == null) return DefaultParentId;
var nav = session.Load<Navigation>(m => m.Name.Equals(priAttr.Name) && m.ParentId.Equals(parentId));
if (nav != null) return nav.Id;
nav = new Navigation
{
Id = GetNavIdByName(session, priAttr.Name),
Name = priAttr.Name,
Type = priAttr.IsMenu ? NavigationType.Module : NavigationType.Action,
Url = GetUrl(area, controller, action),
ParentId = parentId,
OrderId = priAttr.Position,
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
AuthCode = priAttr.NotCheck ? Navigation.NotCheck : Navigation.ShouldCheck,
Status = priAttr.NotCheck ? 1 : 0
};
if (session.Create(nav)) { return nav.Id; }
throw new Exception(string.Format("保存导航失败:Name - {0}, ParentId - {1}", priAttr.Name, parentId));
}
示例3: SaveNavigationContainer
/// <summary>
/// 存储分类
/// </summary>
/// <param name="session">数据库会话</param>
/// <param name="category">导航分类</param>
/// <param name="parentId">导航分类的上级序号</param>
private void SaveNavigationContainer(Session session, NavigationCategory category, long parentId)
{
if (string.IsNullOrEmpty(category.Name))
throw new Exception("Category的Name属性不能为空,请检查nav_container.xml文件");
var nav = session.Load<Navigation>(m => m.Name.Equals(category.Name));
if (nav != null) throw new Exception("Category的Name属性已被使用,请检查nav_container.xml文件");
nav = new Navigation { Id = GetNavIdByName(session, category.Name), Name = category.Name, Type = NavigationType.Category, ParentId = parentId, OrderId = category.OrderId, CreatedAt = DateTime.Now, CreatedBy = "SYSTEM", AuthCode = Navigation.NotCheck };
if (!session.Create(nav))
{
throw new Exception(string.Format("保存导航分类失败:Name - {0}, ParentId - {1}", category.Name, parentId));
}
// 如果是叶子分类,放入导航分类字典备查
if (category.Categories.Count == 0) _navCagotryDict.Add(nav.Name, nav.Id);
foreach (var subCategory in category.Categories)
{
SaveNavigationContainer(session, subCategory, nav.Id);
}
}
示例4: CreatQuestions
private bool CreatQuestions(Exam model, Session session)
{
var count = 1;
if (model.QuestionCount1.HasValue && model.QuestionCount1 != 0)
{
var list = new List<Question>();
if (string.IsNullOrEmpty(model.Answer1))
{
ModelState.AddModelError("Answer1", "答案不能为空!");
return false;
}
var answerList = model.Answer1.Split(',');
if (answerList.Count() != model.QuestionCount1)
{
ModelState.AddModelError("Answer1", "答案个数不匹配!");
return false;
}
if (model.Value1 == null)
{
ModelState.AddModelError("Value1", "分值不能为空!");
return false;
}
if (model.OptionCount1 == null)
{
ModelState.AddModelError("OptionCount1", "选项个数不能为空!");
return false;
}
for (var i = 0; i < model.QuestionCount1; i++)
{
list.Add(new Question
{
No = count++,
ExamId = model.Id,
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
Type = QuestionType.单选,
OptionCount = model.OptionCount1.Value,
Value = model.Value1.Value,
RightAnswer = answerList[i]
});
}
if (!session.Create(list)) return false;
}
if (model.QuestionCount2.HasValue&&model.QuestionCount2 != 0)
{
var list = new List<Question>();
if (string.IsNullOrEmpty(model.Answer2))
{
ModelState.AddModelError("Answer2", "答案不能为空!");
return false;
}
if (model.Value2 == null)
{
ModelState.AddModelError("Value2", "分值不能为空!");
return false;
}
if (model.OptionCount2 == null)
{
ModelState.AddModelError("OptionCount2", "选项个数不能为空!");
return false;
}
var answerList = model.Answer2.Split(',');
if (answerList.Count() != model.QuestionCount2)
{
ModelState.AddModelError("Answer2", "答案个数不匹配!");
return false;
}
for (var i = 0; i < model.QuestionCount2; i++)
{
list.Add(new Question
{
No = count++,
ExamId = model.Id,
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
Type = QuestionType.多选,
OptionCount = model.OptionCount2.Value,
Value = model.Value2.Value,
RightAnswer = answerList[i]
});
}
if (!session.Create(list)) return false;
}
if (model.QuestionCount3.HasValue && model.QuestionCount3 != 0)
{
var list = new List<Question>();
if (string.IsNullOrEmpty(model.Answer3))
{
ModelState.AddModelError("Answer3", "答案不能为空!");
return false;
}
if (model.Value3 == null)
{
ModelState.AddModelError("Value3", "分值不能为空!");
return false;
}
if (model.OptionCount3 == null)
{
ModelState.AddModelError("OptionCount3", "选项个数不能为空!");
return false;
//.........这里部分代码省略.........
示例5: InitAccount
public bool InitAccount(Session session, string currentAccountNo)
{
var account = new Account();
account.Name = Name;
account.Password = Guid.NewGuid().ToString();
account.Status = Account.Inactive;
account.CreatedAt = DateTime.Now;
account.CreatedBy = currentAccountNo;
return session.Create(account);
}
示例6: DeactiveAccount
public bool DeactiveAccount(Session session, string currentAccountNo)
{
var account = session.Load<Account>(m => m.Name.Equals(Name));
if (account == null)
{
account = new Account();
account.Name = Name;
account.Password = Guid.NewGuid().ToString();
account.Status = Account.Inactive;
account.CreatedAt = DateTime.Now;
account.CreatedBy = currentAccountNo;
return session.Create(account);
}
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
return session.Update(account);
}
示例7: DeactiveAccount
private bool DeactiveAccount(Session session, string currentAccountNo)
{
var account = session.Load<Account>(m => m.Name.Equals(Code));
if (account == null)
{
account = new Account
{
Name = Code,
Password = Guid.NewGuid().ToString(),
Status = Account.Inactive,
CreatedAt = DateTime.Now,
CreatedBy = currentAccountNo
};
return session.Create(account);
}
account.Flag = null;
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
return session.Update(account);
}
示例8: AddNotExistAccount
/// <summary>
/// 初始化账户
/// </summary>
/// <param name="session">数据库会话</param>
/// <param name="currentAccountNo">当前账户</param>
/// <returns>是否创建成功</returns>
public bool AddNotExistAccount(Session session, string currentAccountNo)
{
var account = new Account
{
Name = Code, // 账户名实际为工号
Password = Guid.NewGuid().ToString(),
Status = Account.Inactive,
CreatedAt = DateTime.Now,
CreatedBy = currentAccountNo
};
return session.Create(account);
}