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 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; }