Beispiel #1
0
        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;
        }
Beispiel #2
0
        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;
        }