Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
0
 public static void ValidateRiik(Riik riik)
 {
     if (riik == null)
     {
         return;
     }
     if (Utils.IsNullOrEmptyWhitespace(riik.Nimetus))
     {
         throw new Exception("Riigi nimetuse sisestamine on kohustuslik!");
     }
     if (riik.Nimetus.Length > 150)
     {
         throw new Exception("Riigi nimetus saab olla vaid 150 tähemärki!");
     }
     if (Utils.IsNullOrEmptyWhitespace(riik.Tahis))
     {
         throw new Exception("Riigi tahise sisestamine on kohustuslik!");
     }
     if (riik.Tahis.Length > 3)
     {
         throw new Exception("Riigi tahis saab olla vaid 3 tähemärki!");
     }
 }