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 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; }
public static void ValidateLinn(Linn linn) { if (linn == null) { return; } if (Utils.IsNullOrEmptyWhitespace(linn.Nimetus)) { throw new Exception("Linna nimetuse sisestamine on kohustuslik!"); } if (linn.Nimetus.Length > 150) { throw new Exception("Linna nime pikkus saab olla vaid 150 tähemärki!"); } if (linn.RiikID == null) { throw new Exception("Linna riigi sisestamine on kohustuslik!"); } }