Thank you ,
Implementing ConfigTweetTypeCode get/set in CreateOrEditTweetModalViewModel and always using @Model.Tweet.ConfigTweetTypeId in CreateOrEditModalHeader.cshtml (ignoring Model.IsEditMode) did the trick.
if you are after ConfigTweetType then entity is this:
` [Table("ConfigTweetTypes")] public class ConfigTweetType : Entity {
[Required]
[StringLength(ConfigTweetTypeConsts.MaxCodeLength, MinimumLength = ConfigTweetTypeConsts.MinCodeLength)]
public virtual string Code { get; set; }
[Required]
[StringLength(ConfigTweetTypeConsts.MaxDescriptionLength, MinimumLength = ConfigTweetTypeConsts.MinDescriptionLength)]
public virtual string Description { get; set; }
public virtual bool Disabled { get; set; }
}
`
generated ConfigTweetTypeCode is just plain text property:
As I said all code is at the moment generated with Asp.Net Zero tool (VS extension)
` public class CreateOrEditTweetModalViewModel { public CreateOrEditTweetDto Tweet { get; set; }
public string ConfigTweetTypeCode { get; set; }
public string ConfigTweetFrequencyCode { get; set; }
public string UserName { get; set; }
public bool IsEditMode => Tweet.Id.HasValue;
}
`
` public class CreateOrEditTweetDto : EntityDto<int?> {
[Required]
[StringLength(TweetConsts.MaxTitleLength, MinimumLength = TweetConsts.MinTitleLength)]
public string Title { get; set; }
[Required]
[StringLength(TweetConsts.MaxBodyLength, MinimumLength = TweetConsts.MinBodyLength)]
public string Body { get; set; }
[StringLength(TweetConsts.MaxImageFileLength, MinimumLength = TweetConsts.MinImageFileLength)]
public string ImageFile { get; set; }
public DateTime? ValidFrom { get; set; }
public DateTime? ValidTo { get; set; }
public DateTime? NextTweet { get; set; }
public DateTime? LastTweet { get; set; }
public bool Disabled { get; set; }
public int ConfigTweetTypeId { get; set; }
public int ConfigTweetFrequencyId { get; set; }
public long? UserId { get; set; }
}
`
-----------------------
Code is cenerated at the moment usig Zero tool. The goal is simple - user should not be insisted to select Type and Frequency values IF the default ones on screen are ok (the most common is defaulted).
`
<div class="form-group m-form__group">
<label for="ConfigTweetTypeCode">@L("ConfigTweetType")</label>
<div class="input-group">
<input class="form-control" id="ConfigTweetTypeCode" name="configTweetTypeCode" value="@Model.ConfigTweetTypeCode" type="text" disabled>
<div class="input-group-append">
<button class="btn btn-primary blue" id="OpenConfigTweetTypeLookupTableButton" type="button"><i class="fa fa-search"></i> @L("Pick")</button>
</div>
<div class="input-group-prepend">
<button class="btn btn-danger" type="button" id="ClearConfigTweetTypeCodeButton"><i class="fa fa-close"></i></button>
</div>
</div>
</div>
@if (Model.IsEditMode)
{
<input class="form-control" value="@Model.Tweet.ConfigTweetTypeId" type="text" name="configTweetTypeId" required hidden />
}
else
{
<input class="form-control" value="" type="text" name="configTweetTypeId" required hidden />
}
`
I have 15 years C# experience BUT on win apps. EF is not my favourite (as usually my projects involve db with millions of rows ), but ir would be stupid to waste time for recreating basic framework for security, users, rights etc...
Thank you!