Skip to content

Commit

Permalink
Server
Browse files Browse the repository at this point in the history
Dodanie metod webowych do manipulacji danymi Piw.
  • Loading branch information
Montwulf committed Nov 16, 2014
1 parent 2d77e9f commit 02b4ba7
Show file tree
Hide file tree
Showing 29 changed files with 211 additions and 18 deletions.
Binary file modified Browar/Browar.v12.suo
Binary file not shown.
Binary file modified Browar/Browar/bin/Browar.dll
Binary file not shown.
Binary file modified Browar/Browar/bin/Browar.pdb
Binary file not shown.
40 changes: 40 additions & 0 deletions Browar/Browar/obj/Debug/Browar.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,43 @@ C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Browar\obj\Debug\B
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Browar\obj\Debug\Browar.Migrations.Initial1.resources
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Browar\obj\Debug\Browar.Migrations.Initial2.resources
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Browar\obj\Debug\Browar.csprojResolveAssemblyReference.cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Browar.dll.config
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Browar.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Browar.pdb
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Antlr3.Runtime.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\EntityFramework.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\EntityFramework.SqlServer.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Microsoft.Web.Infrastructure.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Newtonsoft.Json.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Net.Http.Formatting.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Helpers.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Http.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Http.WebHost.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Mvc.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Optimization.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Razor.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.WebPages.Deployment.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.WebPages.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.WebPages.Razor.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\WebGrease.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\EntityFramework.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\EntityFramework.SqlServer.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Newtonsoft.Json.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Net.Http.Formatting.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Helpers.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Http.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Http.WebHost.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Mvc.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Optimization.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.Razor.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.WebPages.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.WebPages.Deployment.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\System.Web.WebPages.Razor.xml
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\bin\Antlr3.Runtime.pdb
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.csprojResolveAssemblyReference.cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.Migrations.Initial.resources
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.Migrations.Initial1.resources
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.Migrations.Initial2.resources
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.csproj.GenerateResource.Cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Browar\obj\Debug\Browar.pdb
Binary file modified Browar/Browar/obj/Debug/Browar.csproj.GenerateResource.Cache
Binary file not shown.
Binary file not shown.
Binary file modified Browar/Browar/obj/Debug/Browar.dll
Binary file not shown.
Binary file modified Browar/Browar/obj/Debug/Browar.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
122 changes: 122 additions & 0 deletions Browar/Serwer/DatabaseHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Serwer.DTO;

namespace Serwer
{
public class DatabaseHelper
{
SqlConnection conn;
string query;
public DatabaseHelper()
{
this.conn = new SqlConnection(@"Data Source=montwulfpc\Baza;Initial Catalog=BeersDB; User Id=client; Password=test;");
//string connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
}

public PiwoDetailDTO getBeerWithId(int id)
{
PiwoDetailDTO beer = new PiwoDetailDTO();
this.query = string.Format("SELECT id, nazwa FROM dbo.Browar WHERE id = {0}", id);
using(SqlCommand command = new SqlCommand(this.query, this.conn))
{
conn.Open();

SqlDataReader reader = command.ExecuteReader();
if(reader.HasRows)
{
reader.Read();
beer.Id = int.Parse(reader.GetValue(0).ToString());
beer.Name = reader.GetValue(1).ToString();
}
return beer;
}
}

public List<PiwoDTO> getBeers()
{
List<PiwoDTO> beers = new List<PiwoDTO>();
this.query = string.Format("SELECT id, nazwa FROM dbo.Browar");
using (SqlCommand command = new SqlCommand(this.query, this.conn))
{
conn.Open();

SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
PiwoDTO beer = new PiwoDTO();
beer.Id = int.Parse(reader.GetValue(0).ToString());
beer.Name = reader.GetValue(1).ToString();
beers.Add(beer);
}

return beers;
}
}

public bool updateBeer(PiwoDetailDTO beer)
{
if(this.deleteBeer(beer.Id))
{
if(this.updateBeer(beer))
{
return true;
}
}
return false;
}

public bool deleteBeer(int id)
{
this.query = string.Format("DELETE FROM dbo.Browar WHERE id = {0}", id);
using (SqlCommand command = new SqlCommand(this.query, this.conn))
{
conn.Open();
if (command.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
}

public bool addBeer(PiwoDetailDTO beer)
{
this.query = string.Format("INSERT INTO dbo.Browar (id, nazwa) VALUES ({0}, {1})", beer.Id, beer.Name);
using (SqlCommand command = new SqlCommand(this.query, this.conn))
{
conn.Open();
if (command.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
}

public double getAverageRate(int id)
{
double averageRate = 0;
this.query = string.Format("SELECT AVG(ocena) FROM dbo.Browar WHERE id = {0}", id);
using (SqlCommand command = new SqlCommand(this.query, this.conn))
{
conn.Open();
averageRate = double.Parse(command.ExecuteScalar().ToString());
}
return averageRate;
}

}
}
44 changes: 30 additions & 14 deletions Browar/Serwer/Service.asmx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace Serwer
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
private DatabaseHelper DBHelper;

public Service()
{
DBHelper = new DatabaseHelper();
}

[WebMethod]
public string HelloWorld()
Expand All @@ -28,50 +34,60 @@ public string HelloWorld()
//Metoda wyciąga z tabeli Piwoes wiersz o danym ID i zwraca go w postaci PiwoDTO
//Dodatkowo uzywamy metody policzOcene() do wyliczenia na podstawie danych z bazy sredniej oceny dla naszego piwa i wsadzenie jej do piwo.rate
[WebMethod]
public PiwoDetailDTO GetPiwo(int id)
public PiwoDetailDTO GetBeer(int id)
{
/*Wyciągam z bazy wiersz
* Tworzę obiekt, PiwoDTO piwo = new PiwoDTO();
* I potem odpowiednie wartości przypisujemy.
* np. piwo.Name = wiersz.Name czy jakoś tak
return piwo;*/
return new PiwoDetailDTO();
PiwoDetailDTO beer = DBHelper.getBeerWithId(id);

return beer;
}

//Metoda zwraca wszystkie wiersze z tabeli Piwoes w postaci listy PiwoDTO
//Dodatkowo uzywamy metody policzOcene() do wyliczenia na podstawie danych z bazy sredniej oceny dla nkazdego piwa i wsadzenie jej do piwo.rate każdego z piw
[WebMethod]
public List<PiwoDetailDTO> GetPiwoes()
public List<PiwoDTO> GetBeers()
{
return new List<PiwoDetailDTO>();
List<PiwoDTO> beers = DBHelper.getBeers();
return beers;
}

//Kasuje piwo o danym id i zwraca true albo false czy coś, żeby było wiadomo czy się udało czy nie
[WebMethod]
public bool DeletePiwo(int id)
{
return true;
if(DBHelper.deleteBeer(id))
{
return true;
}
return false;
}

//Przyjmuje PiwoDTO i updateje wiersz o danym id wsadzajac dane hasha, zwraca true false
[WebMethod]
public bool UpdatePiwo(PiwoDetailDTO piwo)
{
return true;
if(DBHelper.updateBeer(piwo))
{
return true;
}
return false;
}

//Wsadza do bazy wiersz z danymi z PiwoDTO, zwraca true/false
[WebMethod]
public bool InsertPiwo(PiwoDetailDTO piwo)
{
return true;
if(DBHelper.addBeer(piwo))
{
return true;
}
return false;
}

//Wyciaga z bazy srednia ocene dla danego piwa
[WebMethod]
public double PoliczOcene(int id)
public double PoliczOcene(int id)
{
return new double();
return DBHelper.getAverageRate(id);
}

//Analogiczne metody, ale nie wszystkie dla User, Comment, Rate, Browarnia
Expand Down
5 changes: 4 additions & 1 deletion Browar/Serwer/Serwer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@
</ItemGroup>
<ItemGroup>
<Content Include="Service.asmx" />
<Content Include="Web.config" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="DatabaseHelper.cs" />
<Compile Include="DTO\PiwoDetailDTO.cs" />
<Compile Include="DTO\PiwoDTO.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Binary file modified Browar/Serwer/bin/Serwer.dll
Binary file not shown.
Binary file modified Browar/Serwer/bin/Serwer.pdb
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions Browar/Serwer/obj/Debug/Serwer.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\bin\Serwer.
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Debug\Serwer.dll
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Debug\Serwer.pdb
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Debug\Serwer.csprojResolveAssemblyReference.cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Debug\Serwer.csprojResolveAssemblyReference.cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Debug\Serwer.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\bin\Serwer.dll.config
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\bin\Serwer.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\bin\Serwer.pdb
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Debug\Serwer.pdb
Binary file not shown.
Binary file modified Browar/Serwer/obj/Debug/Serwer.dll
Binary file not shown.
Binary file modified Browar/Serwer/obj/Debug/Serwer.pdb
Binary file not shown.
Binary file not shown.
Binary file modified Browar/Serwer/obj/Release/Package/PackageTmp/bin/Serwer.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions Browar/Serwer/obj/Release/Package/Serwer.SourceManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<IisApp path="C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Package\PackageTmp" managedRuntimeVersion="v4.0" />
<setAcl path="C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
<IisApp path="D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Package\PackageTmp" managedRuntimeVersion="v4.0" />
<setAcl path="D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Package\PackageTmp" setAclResourceType="Directory" />
<setAcl path="D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>
6 changes: 6 additions & 0 deletions Browar/Serwer/obj/Release/Serwer.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\bin\Serwer.
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Serwer.dll
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Serwer.pdb
C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Serwer.csprojResolveAssemblyReference.cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Serwer.csprojResolveAssemblyReference.cache
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Serwer.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\bin\Serwer.dll.config
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\bin\Serwer.dll
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\bin\Serwer.pdb
D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Serwer.pdb
Binary file not shown.
Binary file modified Browar/Serwer/obj/Release/Serwer.dll
Binary file not shown.
Binary file modified Browar/Serwer/obj/Release/Serwer.pdb
Binary file not shown.
Binary file modified Browar/Serwer/obj/Release/_WPPLastBuildInfo.txt
Binary file not shown.

0 comments on commit 02b4ba7

Please sign in to comment.