Esempio n. 1
0
        public ModRiikResponse AddRiik(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("Lisatav riik puudub!");
                }
                ValidationUtil.ValidateRiik(riik);
                var lisatavRiik = new PtService.NhibernateImpl.DAOs.Impl.Riik();
                lisatavRiik = Utils.CopyTo(riik, lisatavRiik);
                lisatavRiik.ID = 0;
                _connContext._RiikDAO.Save(lisatavRiik);
                resp.ModifiedRiik = new Riik();
                resp.ModifiedRiik = Utils.CopyTo(lisatavRiik, resp.ModifiedRiik);
                resp.Successful = true;
            }
            catch (Exception e)
            {
                resp = new ModRiikResponse();
                resp.Successful = false;
                resp.Exception = e;
            }

            return resp;
        }
Esempio n. 2
0
        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;
        }