Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System.Text;
  2. using System.Threading.Tasks;
  3. using System.Data.Entity;
  4. using TOM.Services.SQL.EF;
  5. using TOM.Services;
  6. using TOM.Models;
  7.  
  8.  
  9. namespace TOM.Services
  10. {
  11. //IUserService = Interface
  12.     public class UserRepository : IUserService
  13.     {
  14.         private TOMEntities _context;
  15.  
  16.         public UserRepository(TOMEntities context)
  17.         {
  18.             _context = context;
  19.         }
  20.  
  21.  
  22.         public SQL.EF.User GetUser(string userName)
  23.         {
  24.             return _context.Users.FirstOrDefault(x => x.UserName == userName);
  25.         }
  26.  
  27.  
  28.         public List<SQL.EF.User> CreateNewUser()
  29.         {
  30.             var userResult = from b in _context.Users
  31.                              select new TOM.Services.SQL.EF.User()
  32.                              {
  33.                                  FirstName = b.FirstName,
  34.                                  LastName = b.LastName,
  35.                                  PhoneNumber = b.PhoneNumber,
  36.                                  UserName = b.UserName,
  37.                                  OrganizationId = b.OrganizationId,
  38.                                  Activated = b.Activated,
  39.                                  RegistrationReasonId = b.RegistrationReasonId,
  40.                                  Admin = b.Admin,
  41.                                  SuperAdmin = b.SuperAdmin,
  42.                                  Created = b.Created,
  43.                                  CreatedBy = b.CreatedBy,
  44.                                  Password = b.Password,
  45.                                  Salt = b.Salt,
  46.                              };
  47.             _context.SaveChanges();
  48.             return userResult.ToList();
  49.  
  50.  
  51.                
  52.         }
  53.  
  54. //INTERFACE
  55. using SIA.Models;
  56. using System;
  57. using System.Collections.Generic;
  58. using System.Linq;
  59. using System.Text;
  60. using System.Threading.Tasks;
  61. using TOM.Services.SQL.EF;
  62.  
  63. namespace SIA.Services
  64. {
  65.    public interface IUserService
  66.     {
  67.        SQL.EF.User GetUser(string userName);
  68.  
  69.        List<SQL.EF.User> CreateNewUser();
  70.     }
  71. }
  72. //SERVICE
  73. using System;
  74. using System.Collections.Generic;
  75. using System.Linq;
  76. using System.Text;
  77. using System.Threading.Tasks;
  78. using SIA.Models;
  79. using System.Net.Mail;
  80. using System.Net;
  81. using System.Configuration;
  82. using SIA.Services.SQL.EF;
  83.  
  84. namespace SIA.Services
  85. {
  86.     public class UserService
  87.     {
  88.         //private string _username;
  89.         private IUserService _userRepository;
  90.  
  91.         public UserService(IUserService userRepository)
  92.         {
  93.             _userRepository = userRepository;
  94.         }
  95.  
  96.  
  97.         public bool UserExist(string userName)
  98.         {
  99.             var user = _userRepository.GetUser(userName);
  100.             return user != null;
  101.         }
  102.  
  103.  
  104.         public SQL.EF.User CreateNewUser()
  105.         {
  106.  
  107.         }
  108.  
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement