Exemplo n.º 1
0
        public ModHooneResponse AddHoone(string sessionHandle, Hoone hoone)
        {
            _connContext = _connContext.CheckDBConn();
            var resp = new ModHooneResponse();
            resp.AuthResponse = validateAuth(sessionHandle);
            if (resp.AuthResponse.IsAuthenticated == false)
            {
                resp.Successful = false;
                resp.Exception = new AuthenticationException(authFailedMsg);
                return resp;
            }

            try
            {
                if (hoone == null)
                {
                    throw new Exception("Lisatav hoone puudub!");
                }
                ValidationUtil.ValidateHoone(hoone);
                var lisatavHoone = new PtService.NhibernateImpl.DAOs.Impl.Hoone();
                lisatavHoone = Utils.CopyTo(hoone, lisatavHoone);
                lisatavHoone.ID = 0;
                _connContext._HooneDAO.Save(lisatavHoone);
                resp.ModifiedHoone = new Hoone();
                resp.ModifiedHoone = Utils.CopyTo(lisatavHoone, resp.ModifiedHoone);
                resp.Successful = true;
            }
            catch (Exception e)
            {
                resp = new ModHooneResponse();
                resp.Successful = false;
                resp.Exception = e;
            }

            return resp;
        }
Exemplo n.º 2
0
        public ModHooneResponse UpdateHoone(string sessionHandle, Hoone hoone)
        {
            _connContext = _connContext.CheckDBConn();
            var resp = new ModHooneResponse();
            resp.AuthResponse = validateAuth(sessionHandle);
            if (resp.AuthResponse.IsAuthenticated == false)
            {
                resp.Successful = false;
                resp.Exception = new AuthenticationException(authFailedMsg);
                return resp;
            }

            try
            {
                if (hoone == null)
                {
                    throw new Exception("Hoone uuendamiseks peab hoone olema sisestatud!");
                }
                if (hoone.ID == 0)
                {
                    throw new Exception("Hoone uuendamiseks peab hoonel olema ID!");
                }
                ValidationUtil.ValidateHoone(hoone);
                var hooneToUpdate = new PtService.NhibernateImpl.DAOs.Impl.Hoone();
                hooneToUpdate = Utils.CopyTo(hoone, hooneToUpdate);
                _connContext._HooneDAO.Update(hooneToUpdate, hooneToUpdate.ID);
                var updatedHoone = new PtService.NhibernateImpl.DAOs.Impl.Hoone();
                updatedHoone =
                    _connContext._HooneDAO.Load(hooneToUpdate.ID, typeof (PtService.NhibernateImpl.DAOs.Impl.Hoone))
                    as PtService.NhibernateImpl.DAOs.Impl.Hoone;
                resp.ModifiedHoone = new Hoone();
                resp.ModifiedHoone = Utils.CopyTo(updatedHoone, resp.ModifiedHoone);
                resp.Successful = true;
            }
            catch (Exception e)
            {
                resp = new ModHooneResponse();
                resp.Successful = false;
                resp.Exception = e;
            }

            return resp;
        }
Exemplo n.º 3
0
 public static void ValidateHoone(Hoone hoone)
 {
     if (hoone == null)
     {
         return;
     }
     if (Utils.IsNullOrEmptyWhitespace(hoone.Nimetus))
     {
         throw new Exception("Hoone nimetuse sisestamine on kohustuslik!");
     }
     if (hoone.Nimetus.Length > 150)
     {
         throw new Exception("Hoone nimi saab olla vaid 150 tähemärki!");
     }
     if (Utils.IsNullOrEmptyWhitespace(hoone.Aadress))
     {
         throw new Exception("Hoone aadressi sisestamine on kohustuslik!");
     }
     if (hoone.Aadress.Length > 200)
     {
         throw new Exception("Hoone aadress saab olla vaid 200 tähemärki!");
     }
     if (hoone.LinnID == null)
     {
         throw new Exception("Hoone linna sisestamine on kohustuslik!");
     }
 }