asp.net mvc - MVC 4 Notification Messages to the User -
i'm using controller - service - repository layer pattern i'm application. repository holds basic crud operations , service layer business logic while controllers kept lean (they call service layer functions).
i want send messages (success, warning, etc.) user i'm unsure how service layer level? i've looked solutions using tempdata , base class seem work on controller level.
is there solution push user notifications view service layer?
looks have separation of concerns in app architecture. wise keep way - not make service layer know ui.
what would create class service layer return execution result.
public class executionresult<t> { public t result { get; set; } public string message { get; set; } }
this way pass message
viewbag.usernotification
, shouw in view:
edit: sample usage:
public class math { public executionresult<double> divide(double number, double divideby) { if (divideby == 0) { return new executionresult<double> { result = double.nan, message = "division 0 not possible" }; } return new executionresult<double> { result = number/divideby }; } }
this sample. in real world take different approach in comparing values of type double
Comments
Post a Comment