Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System;
- using DogVille.Models;
- namespace DogVille
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
- // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
- public class UserService : IUserService
- {
- StringBuilder sb = new StringBuilder();
- #region"Mobile App Web Service"
- public List<ProductResponse> getProductList()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Products");
- var qProduct = from dr in dt.AsEnumerable()
- select new ProductResponse()
- {
- ProductName = dr["ProductName"].ToString(),
- description = dr["description"].ToString(),
- imageUrl =dr["imageURL"].ToString(),
- NoOfViews = dr["NoOfViews"].ToString(),
- price = dr["Price"].ToString(),
- Typeid = dr["Typeid"].ToString(),
- ProductId = dr["ProductId"].ToString()
- };
- return qProduct.ToList();
- }
- public List<UserResponse> getEmployeeList()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT ID,firstname,lastname,email,phone FROM users_info");
- var qUser = from dr in dt.AsEnumerable()
- select new UserResponse()
- {
- id = dr["ID"].ToString(),
- firstName = dr["firstName"].ToString(),
- lastName = dr["lastName"].ToString(),
- email = dr["email"].ToString(),
- phone = dr["phone"].ToString()
- };
- return qUser.ToList();
- }
- public UserResponse getUserByID(string username,string password)
- {
- var dt = (new DBHelper()).GetResultSet(sb.AppendFormat("SELECT FirstName,password FROM users_info WHERE FirstName='{0}' AND password='{1}'", username, password).ToString());
- if (dt.Rows.Count > 0)
- {
- var dr = dt.Rows[0];
- return new UserResponse()
- {
- // id = dr["ID"].ToString(),
- firstName = dr["FirstName"].ToString(),
- // lastName = dr["lastname"].ToString(),
- // email = dr["email"].ToString(),
- phone = dr["password"].ToString()
- };
- }
- return null;
- }
- public RegistrationResponse register(RegistrationRequest request)
- {
- try
- {
- sb.Append("INSERT INTO users_info (firstname,password,phone,email) VALUES ");
- sb.AppendFormat("( '{0}','{1}','{2}','{3}')", request.UserName, request.Password, request.Phone, request.Email);
- (new DBHelper()).SqlExecute(sb.ToString());
- return new RegistrationResponse()
- {
- isSuccessful = true,
- resultMessage = "Register Successfully completed",
- };
- }
- catch (Exception e)
- {
- return new RegistrationResponse()
- {
- isSuccessful = false,
- resultMessage = "Operation not completed",
- };
- }
- }
- public void updateUser(User user)
- {
- sb.Append("UPDATE users_info SET ");
- sb.AppendFormat("( firstname = {0}, lastname = {1},phone = {2}, email = {3} WHERE ID = {4} )", user.firstName, user.lastName, user.phone,user.email, user.id);
- (new DBHelper()).SqlExecute(sb.ToString());
- }
- public void deleteUser(string userID)
- {
- (new DBHelper()).SqlExecute("DELETE FROM user_info WHERE ID =" + userID);
- }
- public LoginResponse login(LoginRequest request)
- {
- var dt = (new DBHelper()).GetResultSet(sb.AppendFormat("SELECT FirstName,password FROM users_info WHERE FirstName='{0}' AND password='{1}'",request.UserName,request.Password).ToString());
- if (dt.Rows.Count > 0)
- {
- return new LoginResponse()
- {
- isSuccessful = true,
- resultMessage = "Login Successfully completed",
- };
- }
- else
- {
- return new LoginResponse()
- {
- isSuccessful = false,
- resultMessage = "UserName or Password are incorrect",
- };
- }
- }
- public List<ProductResponse> getHomeAccessory()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Products WHERE typeid = 5 ORDER BY NoOfViews");
- var qProduct = from dr in dt.AsEnumerable()
- select new ProductResponse()
- {
- ProductName = dr["ProductName"].ToString(),
- description = dr["description"].ToString(),
- imageUrl = dr["imageURL"].ToString(),
- NoOfViews = dr["NoOfViews"].ToString(),
- price = dr["Price"].ToString(),
- Typeid = dr["Typeid"].ToString(),
- ProductId = dr["ProductId"].ToString()
- };
- return qProduct.ToList();
- }
- public List<ProductResponse> getHomePuppies()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Dogs WHERE isOrdered = '1' ORDER BY NoOfViews");
- var qProduct = from dr in dt.AsEnumerable()
- select new ProductResponse()
- {
- ProductId = dr["ProductId"].ToString(),
- ProductName = dr["ProductName"].ToString(),
- description = dr["description"].ToString(),
- imageUrl = dr["imageURL"].ToString(),
- NoOfViews = dr["NoOfViews"].ToString(),
- price = dr["Price"].ToString(),
- Typeid = dr["Typeid"].ToString(),
- };
- return qProduct.ToList();
- }
- public List<ProductResponse> getHomeFood()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Products WHERE Typeid = 1 ORDER BY NoOfViews ");
- var qProduct = from dr in dt.AsEnumerable()
- select new ProductResponse()
- {
- ProductName = dr["ProductName"].ToString(),
- description = dr["description"].ToString(),
- imageUrl = dr["imageURL"].ToString(),
- NoOfViews = dr["NoOfViews"].ToString(),
- price = dr["Price"].ToString(),
- Typeid = dr["Typeid"].ToString(),
- ProductId = dr["ProductId"].ToString()
- };
- return qProduct.ToList();
- }
- public List<ProductResponse> getAllPuppies()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Dogs WHERE isOrdered = '1'");
- var qProduct = from dr in dt.AsEnumerable()
- select new ProductResponse()
- {
- ProductName = dr["DogName"].ToString(),
- description = dr["Description"].ToString(),
- imageUrl = dr["imageURL"].ToString(),
- NoOfViews = dr["NoOfViews"].ToString(),
- price = dr["Price"].ToString(),
- Typeid = dr["GenderID"].ToString(),
- ProductId = dr["dogID"].ToString()
- };
- return qProduct.ToList();
- }
- public BaseResponse setSpecialOrder(PuppyOrderRequest request)
- {
- try
- {
- sb.Append("INSERT INTO dogs (DogName,Description,Imageurl,genderId,ID,isOrdered) VALUES ");
- sb.AppendFormat("( '{0}','{1}','{2}','{3},'{4}','1')", request.puppyName, request.puppyDescription, request.puppyImage,request.puppyGender,request.UserID);
- (new DBHelper()).SqlExecute(sb.ToString());
- return new BaseResponse()
- {
- isSuccessful = true,
- resultMessage = "Register Successfully completed",
- };
- }
- catch (Exception e)
- {
- return new BaseResponse()
- {
- isSuccessful = false,
- resultMessage = "Operation not completed",
- };
- }
- }
- public BaseResponse setProductMessage(ProductMessageRequest request)
- {
- try
- {
- sb.Append("Update dogs set Message = ");
- sb.AppendFormat(" '{0}' WHERE ID = '{1}' AND dogid = '{2}'", request.productMessage, request.userid, request.productid);
- (new DBHelper()).SqlExecute(sb.ToString());
- return new BaseResponse()
- {
- isSuccessful = true,
- resultMessage = "Register Successfully completed",
- };
- }
- catch (Exception e)
- {
- return new BaseResponse()
- {
- isSuccessful = false,
- resultMessage = "Operation not completed",
- };
- }
- }
- public List<TypesModel> getProductTypes()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Types");
- var qProduct = from dr in dt.AsEnumerable()
- select new TypesModel
- {
- TypeName = dr["TypeName"].ToString(),
- TypeId = int.Parse(dr["TypeID"].ToString())
- };
- return qProduct.ToList();
- }
- public List<ProductResponse> getProductsByTypes(String request)
- {
- var dt = (new DBHelper()).GetResultSet(String.Format("SELECT * FROM Products where TypeID = '{0}'",request));
- var qProduct = from dr in dt.AsEnumerable()
- select new ProductResponse()
- {
- ProductName = dr["ProductName"].ToString(),
- description = dr["description"].ToString(),
- imageUrl = dr["imageURL"].ToString(),
- NoOfViews = dr["NoOfViews"].ToString(),
- price = dr["Price"].ToString(),
- Typeid = dr["Typeid"].ToString(),
- ProductId = dr["ProductId"].ToString()
- };
- return qProduct.ToList();
- }
- public TipsModel getTip()
- {
- var dt = (new DBHelper()).GetResultSet("SELECT * FROM Tips");
- var qProduct = from dr in dt.AsEnumerable()
- select new TipsModel()
- {
- Tiptext = dr["Tiptext"].ToString()
- };
- return qProduct.Last();
- }
- public BaseResponse setTipQuestion(TipQuestionRequest tipQuestion)
- {
- try
- {
- sb.Append("INSERT INTO Questions (QuestionText,UserID) VALUES ");
- sb.AppendFormat("( '{0}','{1}')", tipQuestion.question, tipQuestion.userID);
- (new DBHelper()).SqlExecute(sb.ToString());
- return new BaseResponse()
- {
- isSuccessful = true,
- resultMessage = "Register Successfully completed",
- };
- }
- catch (Exception e)
- {
- return new BaseResponse()
- {
- isSuccessful = false,
- resultMessage = "Operation not completed",
- };
- }
- }
- public BaseResponse setOrder(OrderRequest order)
- {
- return new BaseResponse();
- }
- public BaseResponse setNoOfViews(NumberOfViews number)
- {
- try
- {
- sb.Append("Update dogs set NoOfViews = ");
- sb.AppendFormat(" '{2}' WHERE ID = '{1}' AND dogid = '{0}'", number.productID, number.userid, number.numberOfView+1);
- (new DBHelper()).SqlExecute(sb.ToString());
- return new BaseResponse()
- {
- isSuccessful = true,
- resultMessage = "Register Successfully completed",
- };
- }
- catch (Exception e)
- {
- return new BaseResponse()
- {
- isSuccessful = false,
- resultMessage = "Operation not completed",
- };
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement