How to hide that enum value in microsoft bot emulator? - asp.net-web-api

How to avoid that enum values like 1,2 ....i want hide it and i want to display my custom string
public enum Qst1
{
Interact_with_many_including_strangers = 1,
Interact_with_a_few_known_to_you
}
public enum Qst2
{
Realistic_than_speculative = 1,
Speculative_than_realistic
}
[Prompt("At a party do you: {||}")]
public Qst1 A1;
[Prompt(" Are you more:{||}")]
public Qst2 A2;
[Prompt("Is it worse to:{||}")]
public Qst3 A3;
return _order.Field(nameof(Questions.A1)).Field(nameof(Questions.A2))

Related

Validating selection field

I have a property that has an enumeration, in one of the values of the enumeration I have "help", if the user selects that option, I would like to do two things: 1. Send the user a text with help. 2. Ask the user if he wants to continue, or if he wants to leave. I do not know how to do it.
thank you very much.
public enum ContentClassification
{
Confidential_Restricted = 1 ,
Confidential_Secret = 2,
Public = 3,
Strictly_Confidential = 4,
help = 5
};
public ContentClassification ContentClassification { get; set; }
return new FormBuilder()
.Field(nameof(ContentClassification))
You may launch the Form many times, means if you get the "Help" choice from the first Form, launch another form for confirmation.
For example:
public enum ContentClassification
{
Confidential_Restricted = 1,
Confidential_Secret = 2,
Public = 3,
Strictly_Confidential = 4,
help = 5
};
public enum Validating
{
Continue,
Leave
};
[Serializable]
public class Classification
{
public ContentClassification? Choice;
public static IForm<Classification> BuildForm()
{
return new FormBuilder<Classification>()
.Message("You want to")
.Field(nameof(Choice))
.Build();
}
public Validating? Confirmation;
public static IForm<Classification> BuildConfirmForm()
{
return new FormBuilder<Classification>()
.Message("Send your message here")
.Field(nameof(Confirmation))
.Build();
}
}
And then create your RootDialog for example like this:
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
var form = new FormDialog<Classification>(new Classification(), Classification.BuildForm, FormOptions.PromptInStart, null);
context.Call(form, this.GetResultAsync);
return Task.CompletedTask;
}
private async Task GetResultAsync(IDialogContext context, IAwaitable<Classification> result)
{
var state = await result;
if (state.Choice == ContentClassification.help)
{
var form = new FormDialog<Classification>(new Classification(), Classification.BuildConfirmForm, FormOptions.PromptInStart, null);
context.Call(form, null); //change null to your result task here to handle the result.
}
}
}
You still need to implement the logic codes for other options in GetResultAsync method together with the logic codes to handle the result of second form BuildConfirmForm.

LUIS ActionBinding Param Library doesnt display if enum

If I specify as enum then it doesn't get displayed in the dialog. Can anyone help to point out if am missing some thing?
[LuisActionBinding("CollPay", FriendlyName = "Reminder")]
public class CollPayAction : BaseLuisAction
{
public enum PaymentAmtOptions
{
[Terms(new string[] { "Full Payment", "Entire Amount", "Full Due Amount" })]
FullPayment = 1,
[Terms(new string[] { "Clubbed Payment", "Combined Payment" })]
CombinedPayment
};
[Required(ErrorMessage = "Are you planning to make a separate payment or combined one?")]
[LuisActionBindingParam(CustomType = "BOPYMTOPTION", Order = 2)]
[Template(TemplateUsage.EnumSelectOne, "Are you planning to make a separate payment or combined one? {||}",
"How would you like to make the payment - separate for each Invoice(or) clubbed with other pending dues? {||}")]
public PaymentAmtOptions PaymentAmount { get; set; }
public override Task<object> FulfillAsync()
{
var result = string.Format("Hello! You have reached the CollPay intent");
return Task.FromResult((object)result);
}
}
Thanks for reporting this, it was certainly an issue. The good news is that a PR with a patch was already created.
Once the PR is approved, you will have to update your code:
-To use the updated library
-To validate the enum value. Below you will find how the code could look like:
[LuisActionBinding("CollPay", FriendlyName = "Reminder")]
public class CollPayAction : BaseLuisAction
{
public enum PaymentAmtOptions
{
None = 0, // default - no option selected
FullPayment = 1,
CombinedPayment = 2
};
// custom validator for my enum value
public class ValidPaymentAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
return value is PaymentAmtOptions && ((PaymentAmtOptions)value) != PaymentAmtOptions.None;
}
}
[ValidPayment(ErrorMessage = "Are you planning to make a separate payment [FullPayment] or combined one [CombinedPayment]?")]
[LuisActionBindingParam(CustomType = "BOPYMTOPTION", Order = 2)]
public PaymentAmtOptions PaymentAmount { get; set; }
public override Task<object> FulfillAsync()
{
var result = string.Format("Hello! You have reached the CollPay intent");
return Task.FromResult((object)result);
}
}

How to find Difference in two Collections<T> in C#

I have two collections of following class
public class ABC
{
public int studentId {get;set;}
public int schoolId {get;set;}
// Class has other properties too both above two are the keys
}
Now i have two collections of ABC
ICollection<ABC> C1 = {Some Data}
ICollection<ABC> C2 = {Some Data}
I want to find objects of ABC in C1 that are not in C2 based on keys i-e StudentId and SchoolId
Use Except
var diff = C1.Except(C2)
Please also note, that in order to track equality you can override Equals method, or implement and pass IEqualityComparer to Except method
class ABCEqualityComparer : IEqualityComparer<ABC>
{
public bool Equals(ABC b1, ABC b2)
{
return (b1.studentId == b2.studentId) && (b1.schoolId == b2.schoolId)
}
public int GetHashCode(ABC b)
{
return 7*b.studentId.GetHashCode() + b.schoolId.GetHashCode();
}
}
Than you can use
var diff = C1.Except(C2, new ABCEqualityComparer())

How to compare two lists of objects in C#?

Lets say I have a list of objects:
public class MyObject
{
public int ID {get;set;}
public string Name {get;set;}
public DateTime StartDate {get;set;}
}
now the data:
{0, "my", DateTime.Now}
{0, "List", DateTime.Now}
{0, "Data", DateTime.Now}
Now say I stripped this data from an XML or Excel document and I want to compare with what is in the database and Ignore data that already exists. I am using Entity Framework to handle this.
public IEnumerable<MyObject> GetBy()
{
return _context.MyObjects.OrderBy(x => x.Name);
}
I know if you want to get data from a list where it is different you use:
var myNewStuff = myStuff.Except(myDataBaseStuff);
But none of the ID properties will match so that won't work
How do I compare the two lists BASED on the Name AND StartDate values?
You need to implement your own IEqualityComparer and use the overload of Except that takes it. Using Resharper, I generated this one:
public sealed class NameStartDateEqualityComparer : IEqualityComparer<MyObject>
{
public bool Equals(MyObject x, MyObject y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return string.Equals(x.Name, y.Name) && x.StartDate.Equals(y.StartDate);
}
public int GetHashCode(MyObject obj)
{
unchecked
{
return ((obj.Name != null ? obj.Name.GetHashCode() : 0)*397) ^ obj.StartDate.GetHashCode();
}
}
}
Notice that the comparer only examines the Name and StartDate properties. You can of course change the comparer to your liking, like truncating the milliseconds off of the StartDate before comparing them. Then use it as such:
var myNewStuff = myStuff.Except(myDataBaseStuff, new NameStartDateEqualityComparer());

EF/Linq enum error

Given the following code:
public class RMAInfo
{
public enum RMAStatuses {
Undefined = 0, Approved = 1, Denied = 2,
Pending = 3, Received = 4, Closed = 5
}
public enum ReturnLocations { Undefined = 0, Utah = 1, Indy = 2 }
public RMAInfo()
{
ID = -1;
RMACode = string.Empty;
}
public int ID { get; set; }
public string RMACode { get; set; }
public string ResellerID { get; set; }
public RMAStatuses RMAStatus { get; set; }
}
private List<RMAInfo> GetRMAInfos_Internal(string resellerID)
{
List<RMAInfo> returnRMAInfos = new List<RMAInfo>();
using (Models.RMAEntities context = new Models.RMAEntities())
{
returnRMAInfos = (from r in context.RMAs
where r.ResellerID == resellerID
select new RMAInfo
{
ID = r.ID,
RMACode = r.RMACode,
ResellerID = r.ResellerID,
// error on next line!
RMAStatus = RMAInfo.RMAStatuses.Pending
}).ToList();
}
return returnRMAInfos;
}
I am getting an error on the assignment to the RMAStatus field. The error is
The specified value is not an instance of type 'Edm.Int32'
If I comment out that line, it works fine.
I have also tried to do this same code without using EF, and it seems to work fine.
Any ideas?
Entity Framework does not like the enum, as it cannot translate it to SQL. You would need to expose a way for EF to set the underlying int value, or you would have to set the value yourself once EF was done with it.
What you might do is expose an int property to set it. If you wish, you could restrict it to internal access so that perhaps callers can't see it but your EF code can (assuming callers are in different assemblies, but your context is not). Then you could have
public class RMAInfo
{
///<summary>
/// Integer representation of RMAStatus
///</summary>
internal int RMAStatusCode
{
get { return (int)this.RMAStatus; } // you could omit the getter
set { this.RMAStatus = (RMAInfo.RMAStatuses)value; }
}
}
...
select new RMAInfo
{
...
RMAStatusCode = (int)RMAInfo.RMAStatuses.Pending
}
To avoid this, you would basically select your RMAInfo sans status, and then iterate over the result to set each status to pending, leaving EF out of it entirely.
Installing .Net 4.5 appears to fix the issue as well (your project can still be on 4.0).
I was having this issue on our staging server (dev and test servers worked fine) and discovered that it did not have .Net 4.5 installed. Once I installed 4.5, the issue cleared up without any code changes.

Resources