I have to maintain an ASP.net application in VB.Net. There is a page with a FormView bound to a ObjectDataSource. I have to add some business logic on the ItemUpdating event of this FormView. Unfortunately, some the data that I need to add this business logic is not exposed on the FormView user-interface itself, so I can not use FindControl to get the values (I could add the controls, bind them to the fields I need and set their visible property to true, but that's ugly).
So, what I would need to do is to get access to the Data Row corresponding to the currently selected item in the FormView from the code behind as it has the data I need to add my business logic code. Unfortunately, I don't manage to get access to the row.
I was wondering if setting a default value for a SelectList is considered to be presentation logic or business logic? For example, if a requirement is that an Employee cannot be saved without a Location, but 99% of the time the location that would be selected is a particular item -- say Atlanta. Because of this, the location SelectList should be defaulted to Atlanta when ever a entry screen for a new employee is displayed. Should I be defaulting the location in the model or in the view-model? One thing I realized is that the unit tests become awkward because in both cases, I'd be forced to test against a location that will always be present in production but I cannot create a unit test with my own test dataunless "Atlanta" was in the set of locations being used in the test.
I've got a C# MVC 2 application using EF 4. My DAL project gets data from the Model, translates them into POCO's and returns ViewModels to the BLL which is called from the controllers.I've set up validation attributes on the POCO classes and that works for "Required" fields etc. I would like to add business logic such as "From" has to be before the "To" date. Can this be done on the POCO classes so it is automatically validated client-side in the view?
Also, I would like to add some functionality to the BLL layer such as checking if a resource is already booked between the From and To dates to avoid double bookings. This should fire before the ViewModel is saved. I tried a Try/Catch statement in the controller so that I can throw an error in the BLL, but I don't understand how to return this error to the view with an appropriate error message added.
As I am learning and working on Asp.Net MVC application, I want to know that what is the better place to write Business Logic and Data Access logic in MVC.Where should I write DataAccess and Business Logic among three layers (Model, View and Controller) ??Could anybody please tell me the correct way to write the code for this.Scenario: I want to retrieve all the employees where employee name like 'Mi%' ( I have SQL procedure to execute and retrieve the data.)PS: Want to know that where I should create instance of Business Logic class and where I should create instance of Data Access layers class?
I'm building a first MVC app in ASP.NET and I'm using link2SQL model to work with data.All tutorials on the microsoft site let you write LINQ code in the controller to get data and pass it to the view, like this:
Function Index() As ActionResult Dim datacontext As New ErrorVaultDataContext Dim questions = From q In datacontext.Questions
Suppose you have to query a lot of tables and calculate some values and spit it out to the user. Is it ok to have all the business logic for this in the stored procedures? Or is it a better practice to return all the data to the application and do all the data manipulation and rolling up in there?
I'am using enterprise library data access block in my asp.net application. I want to implement transaction from the Business logic layer, across multiple stored procs. Entlib opens a new connection for database access. Does using Transaction Scope in the following way lead to distributed transaction?
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { // calling necessary DAL methods scope.Complete(); }
Is there better methods to implement transaction from BLL?
public int InsertCompanyDetailsInformation(int companyId, int bankId, int accountNo, string accountType) { int rowsAffected = -1; int returnValue; try { SqlConnection con = DBProvider.GetDbConnection(); using (con) { con.Open(); SqlCommand objCmd = new SqlCommand("dbo.sp_InsertCompanyDetailsInformation", con); objCmd.CommandType = CommandType.StoredProcedure; objCmd.Parameters.AddWithValue("@companyId", companyId); objCmd.Parameters.AddWithValue("@bankId", bankId); objCmd.Parameters.AddWithValue("@accountNo", accountNo); objCmd.Parameters.AddWithValue("@accountType", accountType); rowsAffected = objCmd.ExecuteNonQuery(); SqlParameter sqlParam = objCmd.Parameters.Add("@insert_flag", SqlDbType.Int); objCmd.Parameters["@insert_flag"].Direction = ParameterDirection.ReturnValue; returnValue = int.Parse(objCmd.Parameters["@insert_flag"].Value.ToString()); con.Close(); } } catch (Exception ex) { throw ex; } return rowsAffected; } and stored procedure USE [SGTime_Development] GO /****** Object: StoredProcedure [dbo].[sp_InsertCompanyDetailsInformation] Script Date: 01/04/2011 14:31:09 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_InsertCompanyDetailsInformation] ( @companyId int, @bankId int, @accountNo int, @accountType varchar(50)) AS BEGIN SET NOCOUNT ON; declare @insert_flag int; if not exists(select AccountNo from [Company_Account_Details] where AccountNo=@accountNo) begin INSERT INTO [Company_Account_Details] ( Company_Id, BankID, AccountNo, AccountType) values (@companyId, @bankId, @accountNo, @accountType) set @insert_flag=1; END else begin set @insert_flag=-1; end return @insert_flag; end
I am getting error in the code i want return returnValue in InsertCompanyDetailsInformation. how we can return returnValue
This question may have been asked before, but I'm looking for a different answer than what I've seen.
Our website is in ASP.NET and we use the model-view-presenter pattern to get business logic out of the markup codebehind.
Is there an accepted pattern for web services for getting business logic out of the codebehind? It seems like putting the logic in a 'presenter' is misleading since the calls don't really present anything to the user, and may not even send back data to the client.
Currently I am working on a project at work that deals with MVC. I have never used MVC before, only dealt a little with ASP with VB, and that's it. I've dabbled in HTML but not much. I don't currently have the money for a book, so I'm using this forum. So there's a lot of jargon I may not pick up on or may ask a lot of questions, so please bare with me.Anyways here's what I would like to do, or understand. We're using ASP.NET Membership Security (not sure if that's what it's actually called) for passwords and accounts. My issue is that I've been working on other projects while the rest of my team has been working on this, so they know more about it than I do. And I don't want to take too long to understand it, but I have to find the best way to make sure the following doesn't happen:
1) When changing a password, it can't be within the last 10 passwords used for that user.2) When creating/changing a password, it cannot have dictionary words, names, phone numbers or personal data within it.3) The password must be a minimum of 16 characters.Number 3 is rather easy and completed I believe. However, 1 and 2 prove tenuous. We want to store the previous passwords hashed and we were going to save the salt used. However, I'm beginning to think that with the Membership class you can't specify the salt to hash a password. Is there a way to de-hash a password? We do not want to store the passwords as plaintext, so that is out of the question.I believe the best order (for 1 and 2) is to do 2 first (before it's hashed) and then 1. For two, I need to know how to call a function in the Model code from a <submit> tag in the View code. I've done a little research online but thought I'd ask and see if it gets answered while I'm looking for the answer.
In general, my questions are:1) How do I call a function in the ****Model.cs from a <submit> tag in the *******.aspx?2) What's the best way to compare previous passwords that are hashed? 3) If I know the salt, can I de-hash a password? (I believe the answer to this is no.)4) Can I specify the salt to hash a password? (I believe the answer to this is no.)5) If #3 and #4 are no, then should I do encryption instead of hashing?Details: MVC2, C#, Membership.
I am trying to estimate how long it will take to migrate a Classic ASP application to .NET and came across hundreds of COM functions written in VB 6.
A majority of these functions only do parameter validation and actually calls the SQL server. Is this something that should be replace with an ORM? (Linq, nHibernate, Entity Framework)... or should there be more to this picture?
This not an 'MVC' question per se, but this is the closest forum I could find. I am building web/wpf/silverlight front end on the MVP pattern. I am using EDMX and a 'business logic' class to form the model, a presenter project, and a view project.The IViews contain the basic structure of each entity, the presenter contains actions, etc.Sample view:
[Code]....
Sample presenter:
[Code]....
QUESTIONS:I seem to end up with a 1-1 mapping of views and presenters. SHould there be more than one view per presenter, or more than one presenter per view? Should the presenter for an entity (in this case a User) also contain methods for functional items such as searching for a filtered list of Users using overloaded methods, etc.?Should the IViewXYZ interface contain any events or actions (methods)?
I've a static page method in web form application and I want to call method on private class level variable from it as shown below. I'm using jQuery to call the page method.
private readonly ICatalogBLL _catalogBLL = new CatalogBLL(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { _catalogBLL.GetSomething(); } } [WebMethod] public static UpdateSomething(int i) { //Want to do as below. But can't call it from a static method. _catalogBLL.UpdateSomething(); }
UPDATE If I call it as said by John Saunders, won't it use the same instance for requests from different users as it is within a static method?
I've inherited an asp.net web solution, which has business logic and data calls as seperate assemblies. In the business layer there are a small number of calls to get/set HttpContext session values. I've looked around for an example that will allow me to abstract this away from the business logic as I'd like to be able to reuse these assemblies in non-web projects, could anyone please give me an example of the best way to do this. I was thinking of some sort of session factory that will obtain values from some sort of persistant store depending on the usage scenario but I'm new to architecture really and would appreciate a pointer or two.
I know there are a few posts on this issue already, however I haven't found the answers I was really looking for.
My situation is like this: I have a DLL project containing my business logic. Then I have a web application that refers to this DLL, and calls a function from it. And I have a global.asax which handles errors on Application_Error
I have to pass the session value to a business logic layer, I can pass it to the function from presentation layer but how can I access it directly in my business logic layer ? Also is it a good approach to pass it directly to business logic layer like
I have a textbox control i disabled view state at page and control level.i entered a value in the text box and click a button there is a postback,no business logic in the button click event.The values in the testbox are persisting though i disabled at the control level and page level.
After hitting the insert button the insert stored proc is run. if the record already exists then stored proc returns a specific value.I need to refill the details view textboxes with the values the user typed in.I am using the ItemInserted event handler.I seem to reference the control okay but the text doesn't change...even when I replace the command.parameter to just a literal text like "test".
TextBox tNPA = DetailsView1.FindControl("InsertName") as TextBox; tNPA.Text = command.Parameters[0].Value.ToString();
So what am I missing. I also tried a detailsview1.databind() before and then tried after the above line and still no luck.
I am new to this .NET what is the difference between N-Tier and 3- Tier Architecture. If they are same. How to pass the values from presentation layer to business logic layer.
For Example
I have 10 controls in presentation layer. I passing values to these controls. How the architecture works.
I am building a web site following the tutorials on asp.net. I am using dataset as data access lay, and writing classes to access the dataset. But the example is just basic ideas, how do I retrieve individual table column value in the business layer?For example, if I have a table called Product, I only want to find out what is the product name by product id. I did this in my ProductBLL:
public ProductBLL { public int GetProductName(string productId) { ProductDataSet.ProductDataTable prodData = Adapter.GetProductById(productId); [code]...
Is there a better way, or am I doing this correctly? Can anybody give me a reference to a more complicated business logic model?
using an ObjectDataSource and a FormView.In the FormView I have a set of controls. When the FormView is in edition, I have in particular a ComboBox and a TextBox which are related as follows: when the ComboBox takes some special values, the TextBox must be read only or not. or the moment I get that behaviour as follows: the ComboBox triggers a postback when its selected item is changed and in the 'OnPreRender' of my page I get the value of the ComboBox and update the Readonly property of the TextBox accordingly.What I don't like with this method is that I don't use my object model which is consumed by the ObjectDataSource. The problem is simply that when the FormView is in edition there does not seem to be a way to get the instance of the object which is being edited. The 'DataItem' is null and I haven't found any way to automatically build a new object from the values in the controls to pass it to my business layer. Of course I could do the whole job myself by getting explicitly all the values in the controls, but that's not nice.
I am trying to use some page methods on an aspx page. I've done this several times before in other asp.net applications and never had issues until now. I believe that maybe the issue has something to do with the methods be exposed to POST but I'm not entirely sure. Everything on the page loads correctly then once it attempts to make an ajax call rather than hitting the "test" function, the page tries to reload and the page_load method is called again. I chacked the URL string on both cases when page_load is called and both are correct. I am suspicous that there is some need to do with the web.config but I'm not sure what. The application is close to 10 years old and has been grandfathered up all the way to ASP.net 3.5. On another note, I can hit asmx functions perfectly fine its only page methods that seem not to work.
Imports System.Web.Script.Services Imports System.Web.Services Partial Public Class CustomDataFilter[code].....
I found a write-up somewhere about the multi-handle slider control and in the post there were the following javascript lines:
slider.add_value(value); slider.add_drag(value);
Slider, in this case, is my slider control... but how did the person know these two methods exists? Is there an API guide somewhere for the Ajax Control Toolkit?