Функция уже после изменений
[HttpGet]
public DateTime? GetUserBirthday(int userId)
{
var data = _service.GetUserData<UserData>(userId);
if (data?.HiddenFields?.BirthDay == true)
return null;
var user = _service.Get(userId);
if (user != null)
{
var birthday = user.BirthDay;
if (birthday == null)
return null;
if (birthday.Value.Month == 2 && birthday.Value.Day > 28)
return new DateTime(2020, birthday.Value.Month, birthday.Value.Day);
else
return new DateTime(DateTime.Now.Year, birthday.Value.Month, birthday.Value.Day);
}
return null;
}
функция до изменений
[HttpGet]
public DateTime? GetUserBirthday(int userId)
{
var data = _service.GetUserData<UserData>(userId);
if (data?.HiddenFields?.BirthDay == true)
return null;
var user = _service.Get(userId);
var birthday = user.BirthDay;
if (birthday == null)
return null;
if(birthday.Value.Month == 2 && birthday.Value.Day > 28)
return new DateTime(2020, birthday.Value.Month, birthday.Value.Day);
else
return new DateTime(DateTime.Now.Year, birthday.Value.Month, birthday.Value.Day);
}
и есть вопрос:
А не проще было бы в этом условии if (birthday == null) добавить " || user == null" ?