如何检查是否已填充ViewModel的任何属性

时间:2017-10-16 10:59:39

标签: c# asp.net-core viewmodel

我有一个ViewModel,其中包含可以从我的网络应用程序的用户填写可选的属性(例如,名字,姓氏,电子邮件,出生日期等)。这些属性包括几种类型,如string,bool int,decimal,double,DateTime。在ViewModel中,所有这些类型都可以是可空的和不可为空的。

如果填写了至少其中一个属性,那么我必须创建一个数据库记录。您是否知道如何检查是否已填充这些可选值?

2 个答案:

答案 0 :(得分:0)

按照惯例,原始数据类型是必需的。你可以使属性为nullable,它们是原始的,如int,double,DateTime vs. Then:

from __future__ import unicode_literals  # Put this at the top of your source

eng = 'ETOPAHKXCBMetopahkxcbm' # English letters
rus = 'ЕТОРАНКХСВМеторанкхсвм' # Russian letters

table = dict(zip(map(ord, eng), map(ord, rus)))
assert eng.translate(table) == rus    # Verifying translation

答案 1 :(得分:0)

您可以实现此代码,传递您的viewmodel,然后计算多少字段不为null,如果返回值> 0 ,那么您可以实现您的Db工作。

definitions:
  User:
    description: "User"
    type: "object"
    properties:
      firstname:
        type: "string"
      lastname:
        type: "string"
      password:
        type: "string"
      email:
        type: "string"
      username:
        type: "string"
相关问题