public static PtService.NhibernateImpl.DAOs.Impl.Kasutaja CheckValidateHandle(string validateHandle, DaoConnContext connContext) { if (Utils.IsNullOrEmptyWhitespace(validateHandle)) { throw new Exception("Valideerimise ID on tühi!"); } if (!Utils.IsDigitsOnly(validateHandle)) { throw new Exception("Valideerimise ID formaat ei vasta nõuetele!"); } if (validateHandle.Length != 40) { throw new Exception("Valideerimise ID pikkus ei ole sobiv!"); } PtService.NhibernateImpl.DAOs.Impl.Kasutaja kasutaja = connContext._KasutajaDAO.GetKasutaja(validateHandle); if (kasutaja == null) { throw new Exception("Valideerimise ebaõnnestus kasutaja sessiooni puudumise tõttu!"); } if (kasutaja.SessionValidTo != null && kasutaja.SessionValidTo > DateTime.Now) { throw new Exception("Valideerimise ebaõnnestus kasutaja sessiooni lõppnevuse tõttu!"); } if (kasutaja.LoppKP != null && kasutaja.LoppKP >= DateTime.Now) { throw new Exception("Valideerimise ebaõnnestus kasutaja lõppnevuse tõttu!"); } return kasutaja; }
public ModAtribuutikaLiikResponse AddAtribuutikaLiik(string sessionHandle, AtribuutikaLiik atribuutikaLiik) { _connContext = _connContext.CheckDBConn(); var resp = new ModAtribuutikaLiikResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (atribuutikaLiik == null) { throw new Exception("Lisatav atribuutika liik puudub!"); } ValidationUtil.ValidateAtribuutikaLiik(atribuutikaLiik); var lisatavAtribuutikaLiik = new PtService.NhibernateImpl.DAOs.Impl.Atribuutika(); lisatavAtribuutikaLiik = Utils.CopyTo(atribuutikaLiik, lisatavAtribuutikaLiik); lisatavAtribuutikaLiik.ID = 0; _connContext._AtribuutikaLiikDAO.Save(lisatavAtribuutikaLiik); resp.ModifiedAtribuutikaLiik = new AtribuutikaLiik(); resp.ModifiedAtribuutikaLiik = Utils.CopyTo(lisatavAtribuutikaLiik, resp.ModifiedAtribuutikaLiik); resp.Successful = true; } catch (Exception e) { resp = new ModAtribuutikaLiikResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public StandardResponse RemoveAtribuutika(string sessionHandle, int atribuutikaId) { _connContext = _connContext.CheckDBConn(); var resp = new StandardResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (atribuutikaId == 0) { throw new Exception("Atribuutika eemaldamiseks peab atribuutika ID olema sisestatud!"); } var AtribuutikaToDel = _connContext._AtribuutikaDao.Load(atribuutikaId, typeof (PtService.NhibernateImpl.DAOs.Impl.Atribuutika)) as PtService.NhibernateImpl.DAOs.Impl.Atribuutika; _connContext._AtribuutikaDao.Delete(AtribuutikaToDel); resp.Successful = true; } catch (Exception e) { resp = new StandardResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModGetAllUsersResponse GetAllUsers(string sessionHandle) { _connContext = _connContext.CheckDBConn(); var resp = new ModGetAllUsersResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { IList elems = _connContext._KasutajaDAO.LoadAll(typeof(PtService.NhibernateImpl.DAOs.Impl.Kasutaja)); resp.AllUsers = Utils.ConvertToType<Kasutaja>(elems); resp.Successful = true; } catch (Exception e) { resp = new ModGetAllUsersResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public AuthResponse AuthUser(string userName, string psswdHash) { _connContext = _connContext.CheckDBConn(); var resp = new AuthResponse(); try { ValidationUtil.ValidateAuthInput(userName, psswdHash); PtService.NhibernateImpl.DAOs.Impl.Kasutaja principal = _connContext._KasutajaDAO.GetKasutaja(userName, psswdHash); if (principal == null) { throw new Exception("Kasutaja autentimine ebaõnnestus!"); } else if (principal.LoppKP > DateTime.Now) { throw new Exception("Puudub kehtiv kasutaja!"); } else if (principal.IsikID == null) { throw new Exception("Kasutajal puudub isik!"); } string validHandle = Utils.GenCryptoRndStr(); DateTime sessValidTo = DateTime.Now.AddMinutes(15); principal.SessionHandle = validHandle; principal.SessionValidTo = sessValidTo; _connContext._KasutajaDAO.Update(principal, principal.ID); resp.IsAuthenticated = true; resp.SessionValidFrom = DateTime.Now; resp.SessionHandle = validHandle; resp.SessionValidTo = sessValidTo; resp.Kasustaja = new Kasutaja(); resp.Kasustaja = Utils.CopyTo(principal, resp.Kasustaja); } catch (Exception exception) { resp = new AuthResponse {IsAuthenticated = false, AuthException = exception}; } return resp; }
public ModUserResponse AddUser(string sessionHandle, Kasutaja user) { _connContext = _connContext.CheckDBConn(); var resp = new ModUserResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (user == null) { throw new Exception("Lisatav kasutaja puudub!"); } ValidationUtil.ValidateKasutaja(user, false); var lisatavKasutaja = new PtService.NhibernateImpl.DAOs.Impl.Kasutaja(); lisatavKasutaja = Utils.CopyTo(user, lisatavKasutaja); lisatavKasutaja.ID = 0; _connContext._KasutajaDAO.Save(lisatavKasutaja); resp.ModifiedUser = new Kasutaja(); resp.ModifiedUser = Utils.CopyTo(lisatavKasutaja, resp.ModifiedUser); resp.Successful = true; } catch (Exception e) { resp = new ModUserResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModOsakondResponse AddOsakond(string sessionHandle, Osakond osakond) { _connContext = _connContext.CheckDBConn(); var resp = new ModOsakondResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (osakond == null) { throw new Exception("Lisatav osakond puudub!"); } ValidationUtil.ValidateOsakond(osakond); var lisatavOsakond = new PtService.NhibernateImpl.DAOs.Impl.Osakond(); lisatavOsakond = Utils.CopyTo(osakond, lisatavOsakond); lisatavOsakond.ID = 0; _connContext._OsakondDAO.Save(lisatavOsakond); resp.ModifiedOsakond = new Osakond(); resp.ModifiedOsakond = Utils.CopyTo(lisatavOsakond, resp.ModifiedOsakond); resp.Successful = true; } catch (Exception e) { resp = new ModOsakondResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModHooneResponse AddHoone(string sessionHandle, Hoone hoone) { _connContext = _connContext.CheckDBConn(); var resp = new ModHooneResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (hoone == null) { throw new Exception("Lisatav hoone puudub!"); } ValidationUtil.ValidateHoone(hoone); var lisatavHoone = new PtService.NhibernateImpl.DAOs.Impl.Hoone(); lisatavHoone = Utils.CopyTo(hoone, lisatavHoone); lisatavHoone.ID = 0; _connContext._HooneDAO.Save(lisatavHoone); resp.ModifiedHoone = new Hoone(); resp.ModifiedHoone = Utils.CopyTo(lisatavHoone, resp.ModifiedHoone); resp.Successful = true; } catch (Exception e) { resp = new ModHooneResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModUserResponse UpdateUser(string sessionHandle, Kasutaja user) { _connContext = _connContext.CheckDBConn(); var resp = new ModUserResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (user == null) { throw new Exception("Kasutaja uuendamiseks peab kasutaja olema sisestatud!"); } if (user.ID == 0) { throw new Exception("Kasutaja uuendamiseks peab kasutajal olema ID!"); } ValidationUtil.ValidateKasutaja(user, true); var kasutajaToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Kasutaja(); kasutajaToUpdate = Utils.CopyTo(user, kasutajaToUpdate); _connContext._IsikDAO.Update(kasutajaToUpdate, kasutajaToUpdate.ID); var updatedIsik = new PtService.NhibernateImpl.DAOs.Impl.Kasutaja(); updatedIsik = _connContext._KasutajaDAO.Load(kasutajaToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Kasutaja)) as PtService.NhibernateImpl.DAOs.Impl.Kasutaja; resp.ModifiedUser = new Kasutaja(); resp.ModifiedUser = Utils.CopyTo(updatedIsik, resp.ModifiedUser); resp.Successful = true; } catch (Exception e) { resp = new ModUserResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModRiikResponse UpdateRiik(string sessionHandle, Riik riik) { _connContext = _connContext.CheckDBConn(); var resp = new ModRiikResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (riik == null) { throw new Exception("Riigi uuendamiseks peab riik olema sisestatud!"); } if (riik.ID == 0) { throw new Exception("Riigi uuendamiseks peab riigil olema ID!"); } ValidationUtil.ValidateRiik(riik); var RiikToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Riik(); RiikToUpdate = Utils.CopyTo(riik, RiikToUpdate); _connContext._RiikDAO.Update(RiikToUpdate, RiikToUpdate.ID); var updatedRiik = new PtService.NhibernateImpl.DAOs.Impl.Riik(); updatedRiik = _connContext._RiikDAO.Load(RiikToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Riik)) as PtService.NhibernateImpl.DAOs.Impl.Riik; resp.ModifiedRiik = new Riik(); resp.ModifiedRiik = Utils.CopyTo(updatedRiik, resp.ModifiedRiik); resp.Successful = true; } catch (Exception e) { resp = new ModRiikResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModOsakondResponse UpdateOsakond(string sessionHandle, Osakond osakond) { _connContext = _connContext.CheckDBConn(); var resp = new ModOsakondResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (osakond == null) { throw new Exception("Osakonna uuendamiseks peab osakond olema sisestatud!"); } if (osakond.ID == 0) { throw new Exception("Osakonna uuendamiseks peab osakonnal olema ID!"); } ValidationUtil.ValidateOsakond(osakond); var osakondToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Osakond(); osakondToUpdate = Utils.CopyTo(osakond, osakondToUpdate); _connContext._OsakondDAO.Update(osakondToUpdate, osakondToUpdate.ID); var updatedOsakond = new PtService.NhibernateImpl.DAOs.Impl.Osakond(); updatedOsakond = _connContext._OsakondDAO.Load(osakondToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Osakond)) as PtService.NhibernateImpl.DAOs.Impl.Osakond; resp.ModifiedOsakond = new Osakond(); resp.ModifiedOsakond = Utils.CopyTo(updatedOsakond, resp.ModifiedOsakond); resp.Successful = true; } catch (Exception e) { resp = new ModOsakondResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModLinnResponse UpdateLinn(string sessionHandle, Linn linn) { _connContext = _connContext.CheckDBConn(); var resp = new ModLinnResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (linn == null) { throw new Exception("Linna uuendamiseks peab linn olema sisestatud!"); } if (linn.ID == 0) { throw new Exception("Linna uuendamiseks peab linnal olema ID!"); } ValidationUtil.ValidateLinn(linn); var LinnToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Linn(); LinnToUpdate = Utils.CopyTo(linn, LinnToUpdate); _connContext._LinnDAO.Update(LinnToUpdate, LinnToUpdate.ID); var updatedLinn = new PtService.NhibernateImpl.DAOs.Impl.Linn(); updatedLinn = _connContext._LinnDAO.Load(LinnToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Linn)) as PtService.NhibernateImpl.DAOs.Impl.Linn; resp.ModifiedLinn = new Linn(); resp.ModifiedLinn = Utils.CopyTo(updatedLinn, resp.ModifiedLinn); resp.Successful = true; } catch (Exception e) { resp = new ModLinnResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModHooneResponse UpdateHoone(string sessionHandle, Hoone hoone) { _connContext = _connContext.CheckDBConn(); var resp = new ModHooneResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (hoone == null) { throw new Exception("Hoone uuendamiseks peab hoone olema sisestatud!"); } if (hoone.ID == 0) { throw new Exception("Hoone uuendamiseks peab hoonel olema ID!"); } ValidationUtil.ValidateHoone(hoone); var hooneToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Hoone(); hooneToUpdate = Utils.CopyTo(hoone, hooneToUpdate); _connContext._HooneDAO.Update(hooneToUpdate, hooneToUpdate.ID); var updatedHoone = new PtService.NhibernateImpl.DAOs.Impl.Hoone(); updatedHoone = _connContext._HooneDAO.Load(hooneToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Hoone)) as PtService.NhibernateImpl.DAOs.Impl.Hoone; resp.ModifiedHoone = new Hoone(); resp.ModifiedHoone = Utils.CopyTo(updatedHoone, resp.ModifiedHoone); resp.Successful = true; } catch (Exception e) { resp = new ModHooneResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModAtribuutikaResponse UpdateAtribuutika(string sessionHandle, Atribuutika atribuutika) { _connContext = _connContext.CheckDBConn(); var resp = new ModAtribuutikaResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (atribuutika == null) { throw new Exception("Atribuutika uuendamiseks peab atribuutika olema sisestatud!"); } if (atribuutika.ID == 0) { throw new Exception("Atribuutika uuendamiseks peab atribuutikal olema ID!"); } ValidationUtil.ValidateAtribuutika(atribuutika); var atribuutikaToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Atribuutika(); atribuutikaToUpdate = Utils.CopyTo(atribuutika, atribuutikaToUpdate); _connContext._AtribuutikaDao.Update(atribuutikaToUpdate, atribuutikaToUpdate.ID); var updatedAtribuutika = new PtService.NhibernateImpl.DAOs.Impl.Atribuutika(); updatedAtribuutika = _connContext._AtribuutikaDao.Load(atribuutikaToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Atribuutika)) as PtService.NhibernateImpl.DAOs.Impl.Atribuutika; resp.ModifiedAtribuutika = new Atribuutika(); resp.ModifiedAtribuutika = Utils.CopyTo(updatedAtribuutika, resp.ModifiedAtribuutika); resp.Successful = true; } catch (Exception e) { resp = new ModAtribuutikaResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public StandardResponse RemoveUser(string sessionHandle, int userId) { _connContext = _connContext.CheckDBConn(); var resp = new StandardResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (userId == 0) { throw new Exception("Kasutaja eemaldamiseks peab kasutaja ID olema sisestatud!"); } var UserToDel = _connContext._KasutajaDAO.Load(userId, typeof (PtService.NhibernateImpl.DAOs.Impl.Kasutaja)) as PtService.NhibernateImpl.DAOs.Impl.Kasutaja; _connContext._KasutajaDAO.Delete(UserToDel); resp.Successful = true; } catch (Exception e) { resp = new StandardResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public StandardResponse RemoveIsikGraafik(string sessionHandle, int isikGraafikId) { _connContext = _connContext.CheckDBConn(); var resp = new StandardResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (isikGraafikId == 0) { throw new Exception("Isiku graafiku eemaldamiseks peab isiku graafiku ID olema sisestatud!"); } var isikGraafikToDel = _connContext._IsikGraafikDAO.Load(isikGraafikId, typeof (PtService.NhibernateImpl.DAOs.Impl.IsikGraafik)) as PtService.NhibernateImpl.DAOs.Impl.IsikGraafik; _connContext._IsikGraafikDAO.Delete(isikGraafikToDel); resp.Successful = true; } catch (Exception e) { resp = new StandardResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public StandardResponse RemoveOsakond(string sessionHandle, int osakond) { _connContext = _connContext.CheckDBConn(); var resp = new StandardResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (osakond == 0) { throw new Exception("Osakonna eemaldamiseks peab osakonna ID olema sisestatud!"); } var osakondToDel = _connContext._OsakondDAO.Load(osakond, typeof (PtService.NhibernateImpl.DAOs.Impl.Osakond)) as PtService.NhibernateImpl.DAOs.Impl.Osakond; _connContext._OsakondDAO.Delete(osakondToDel); resp.Successful = true; } catch (Exception e) { resp = new StandardResponse(); resp.Successful = false; resp.Exception = e; } return resp; }
public ModLinnResponse AddLinn(string sessionHandle, Linn linn) { _connContext = _connContext.CheckDBConn(); var resp = new ModLinnResponse(); resp.AuthResponse = validateAuth(sessionHandle); if (resp.AuthResponse.IsAuthenticated == false) { resp.Successful = false; resp.Exception = new AuthenticationException(authFailedMsg); return resp; } try { if (linn == null) { throw new Exception("Lisatav linn puudub!"); } ValidationUtil.ValidateLinn(linn); var lisatavLinn = new PtService.NhibernateImpl.DAOs.Impl.Linn(); lisatavLinn = Utils.CopyTo(linn, lisatavLinn); lisatavLinn.ID = 0; _connContext._LinnDAO.Save(lisatavLinn); resp.ModifiedLinn = new Linn(); resp.ModifiedLinn = Utils.CopyTo(lisatavLinn, resp.ModifiedLinn); resp.Successful = true; } catch (Exception e) { resp = new ModLinnResponse(); resp.Successful = false; resp.Exception = e; } return resp; }