Dev
Dev

Reputation: 137

I want help in calling below Stored procedure into my MVC model

I have this stored procedure written in SQL Server.

USE [AppMarketplace]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[uspTerms] 
@ID int

AS
BEGIN
SET NOCOUNT ON;

if(exists(select * from AppmarketApp where ID= @ID)) -- checking whether user exists in main user table

BEGIN
 if(exists(select * from AppTerms where ID = @ID)) -- if exists in the main table then check in terms table for accepting condition

BEGIN
return 1; -- if user has accepeted terms and condition
End

else
Begin
return 0; --if user not accepetd terms and codition
end
end

begin 
return -1; --if user doesnt exists in AppmarketApp table
end
end

GO

Now I have to call this in my MVC Model.I am using EF Database first approach. My first question is

1) Do i need to call SP in Model or controller? explanation with code would be better.

2) And also I am looking for code to this scenario : I need to write logic to check whether user accepted terms and condition. If user not accepted terms then I should display terms and condition page and force them to accept. How it exactly works is first I will check my Appterms table.In this table I have two fields called ID and Date.If user accept terms then date when user accepted will be stored in this table with thier ID. So if datefield is empty for userID it means they have not accepeted terms and conditon..

Upvotes: 0

Views: 659

Answers (2)

Andrey Gubal
Andrey Gubal

Reputation: 3479

There are some detailed tutorials on asp.net web site. You didn't mentioned what approach you use for database connection, so if you are using ADO.Net model read following:

http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-7

If you use Code First you have to call SP manually:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application

Upvotes: 0

Colin Bacon
Colin Bacon

Reputation: 15609

1) Do i need to call SP in Model or controller? explanation with code would be better.

Neither, your stored procedure call should be in your business logic layer. The controller is really a presentation layer and should only deal getting data and passing it onto your view.

Your model or ViewModel should not have any business logic tied up in it either, it should really be a DTO.

Upvotes: 1

Related Questions