示例#1
0
        public ModIsikResponse AddIsik(string sessionHandle, Isik isik)
        {
            _connContext = _connContext.CheckDBConn();
            var resp = new ModIsikResponse();
            resp.AuthResponse = validateAuth(sessionHandle);
            if (resp.AuthResponse.IsAuthenticated == false)
            {
                resp.Successful = false;
                resp.Exception = new AuthenticationException(authFailedMsg);
                return resp;
            }

            try
            {
                if (isik == null)
                {
                    throw new Exception("Lisatav isik puudub!");
                }
                ValidationUtil.ValidateIsik(isik);
                var lisatavIsik = new PtService.NhibernateImpl.DAOs.Impl.Isik();
                lisatavIsik = Utils.CopyTo(isik, lisatavIsik);
                lisatavIsik.ID = 0;
                _connContext._IsikDAO.Save(lisatavIsik);
                resp.ModifiedIsik = Utils.CopyTo(lisatavIsik, resp.ModifiedIsik);
                resp.Successful = true;
            }
            catch (Exception e)
            {
                resp = new ModIsikResponse();
                resp.Successful = false;
                resp.Exception = e;
            }

            return resp;
        }
示例#2
0
        public ModIsikResponse UpdateIsik(string sessionHandle, Isik isik)
        {
            _connContext = _connContext.CheckDBConn();
            var resp = new ModIsikResponse();
            resp.AuthResponse = validateAuth(sessionHandle);
            if (resp.AuthResponse.IsAuthenticated == false)
            {
                resp.Successful = false;
                resp.Exception = new AuthenticationException(authFailedMsg);
                return resp;
            }

            try
            {
                if (isik == null)
                {
                    throw new Exception("Isiku uuendamiseks peab isik olema sisestatud!");
                }
                if (isik.ID == 0)
                {
                    throw new Exception("Isiku uuendamiseks peab isikul olema ID!");
                }
                ValidationUtil.ValidateIsik(isik);
                var isikToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Isik();
                isikToUpdate = Utils.CopyTo(isik, isikToUpdate);
                _connContext._IsikDAO.Update(isikToUpdate, isikToUpdate.ID);
                var updatedIsik = new PtService.NhibernateImpl.DAOs.Impl.Isik();
                updatedIsik =
                    _connContext._IsikDAO.Load(isikToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Isik))
                    as PtService.NhibernateImpl.DAOs.Impl.Isik;
                resp.ModifiedIsik = new Isik();
                resp.ModifiedIsik = Utils.CopyTo(updatedIsik, resp.ModifiedIsik);
                resp.Successful = true;
            }
            catch (Exception e)
            {
                resp = new ModIsikResponse();
                resp.Successful = false;
                resp.Exception = e;
            }

            return resp;
        }