Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Security.ADODataAccess/3.2/HLUserAdapter.cs @ 1656

Last change on this file since 1656 was 1656, checked in by svonolfe, 15 years ago

Implemented large parts of the security DAL (#597)

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.DataAccess.ADOHelper;
6using HeuristicLab.Security.Contracts.BusinessObjects;
7using HeuristicLab.Security.DataAccess;
8using HeuristicLab.Security.ADODataAccess.TableAdapterWrapper;
9
10namespace HeuristicLab.Security.ADODataAccess {
11  class HLUserAdapter: DataAdapterBase<
12      dsSecurityTableAdapters.HLUserTableAdapter,
13      User,
14      dsSecurity.HLUserRow>,
15      IUserAdapter {
16    public HLUserAdapter() :
17      base(new HLUserAdapterWrapper()) {
18    }
19
20    private IPermissionOwnerAdapter permOwnerAdapter = null;
21
22    private IPermissionOwnerAdapter PermOwnerAdapter {
23      get {
24        if (permOwnerAdapter == null)
25          permOwnerAdapter =
26            this.Session.GetDataAdapter<PermissionOwner, IPermissionOwnerAdapter>();
27
28        return permOwnerAdapter;
29      }
30    }
31
32    protected override dsSecurity.HLUserRow ConvertObj(User user, dsSecurity.HLUserRow row) {
33      if (user != null && row != null) {
34        row.PermissionOwnerId = user.Id;
35
36        return row;
37      } else {
38        return null;
39      }
40    }
41
42    protected override User ConvertRow(dsSecurity.HLUserRow row, User user) {
43      if (user != null && row != null) {
44        /*Parent - permissionOwner*/
45        user.Id = row.PermissionOwnerId;
46        PermOwnerAdapter.GetById(user);
47
48        if (!row.IsLoginNull())
49          user.Login = row.Login;
50        else
51          user.Login = String.Empty;
52
53        if (!row.IsPasswordNull())
54          user.Password = row.Password;
55        else
56          user.Password = String.Empty;
57
58        if (!row.IsMailAddressNull())
59          user.MailAddress = row.MailAddress;
60        else
61          user.MailAddress = String.Empty;
62
63        return user;
64      } else {
65        return null;
66      }
67    }
68
69    #region IUserAdapter Members
70
71    protected override void doUpdate(User user) {
72      if (user != null) {
73        PermOwnerAdapter.Update(user);
74
75        base.doUpdate(user);
76      }
77    }
78
79    protected override bool doDelete(User user) {
80      bool success = false;
81
82      if (user != null) {
83        dsSecurity.HLUserRow row =
84          GetRowById(user.Id);
85
86        if (row != null) {
87          success = base.doDelete(user) &&
88            PermOwnerAdapter.Delete(user);
89        }
90      }
91
92      return success;
93    }
94
95    public User GetByName(string name)
96    {
97      User user = new User();
98      PermissionOwner permOwner =
99        PermOwnerAdapter.GetByName(name);
100
101      return GetById(permOwner.Id);
102    }
103
104    #endregion
105}
106}
Note: See TracBrowser for help on using the repository browser.