Esempio n. 1
0
        public static OvlascenaLicaModel GetAuthorizedPersonById(int Id)
        {
            OvlascenaLicaModel grad = null;

            SqlConnection connection = Database.GetConnection();
            SqlCommand    cmd        = null;
            SqlDataReader reader     = null;

            connection.Open();
            cmd = new SqlCommand(GET_AUTHORIZED_PERSON_BY_ID, connection);
            cmd.Parameters.AddWithValue("@AutoID", Id);
            cmd.CommandTimeout = 60;
            reader             = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    grad                = new OvlascenaLicaModel();
                    grad.AutoID         = reader.GetInt32(0);
                    grad.Uvoznik.AutoID = reader.GetInt32(1);
                    if (!reader.IsDBNull(2))
                    {
                        grad.DodatnoOvlascenoLice = reader.GetString(2);
                    }
                }
                reader.Close();
            }
            connection.Close();

            return(grad);
        }
Esempio n. 2
0
        public static List <OvlascenaLicaModel> GetAllAuthorizedPersons(int UvoznikID)
        {
            List <OvlascenaLicaModel> ovlascenaLicaModels = new List <OvlascenaLicaModel>();
            OvlascenaLicaModel        lice = null;

            SqlConnection connection = Database.GetConnection();
            SqlCommand    cmd        = null;
            SqlDataReader reader     = null;

            connection.Open();
            cmd = new SqlCommand(GET_ALL_AUTHORIZED_PERSONS, connection);
            cmd.Parameters.AddWithValue("@UvoznikID", UvoznikID);
            cmd.CommandTimeout = 60;
            reader             = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    lice                = new OvlascenaLicaModel();
                    lice.AutoID         = reader.GetInt32(0);
                    lice.Uvoznik.AutoID = reader.GetInt32(1);
                    if (!reader.IsDBNull(2))
                    {
                        lice.DodatnoOvlascenoLice = reader.GetString(2);
                    }
                    ovlascenaLicaModels.Add(lice);
                }
                reader.Close();
            }
            connection.Close();

            return(ovlascenaLicaModels);
        }
 public void SaveID([FromBody] OvlascenaLicaModel ovlascenoLicaModel)
 {
     try
     {
         HttpContext.Session.SetInt32("OvlastenoLiceID", ovlascenoLicaModel.AutoID);
     }
     catch (Exception)
     {
     }
 }
        // GET: City/Delete/5
        public bool Delete([FromBody] OvlascenaLicaModel ovlascenoLicaModel)
        {
            try
            {
                return(OvlascenaLicaDAO.DeleteAuthorizedPerson(ovlascenoLicaModel.AutoID));
            }
            catch (Exception)
            {
            }

            return(false);
        }
Esempio n. 5
0
        public static Boolean CreateNewAuthorizedPerson(OvlascenaLicaModel lice)
        {
            Boolean created;

            SqlConnection connection = Database.GetConnection();
            SqlCommand    cmd        = null;

            connection.Open();
            cmd = new SqlCommand(CREATE_NEW_AUTHORIZED_PERSON, connection);
            cmd.Parameters.AddWithValue("@UvoznikID", lice.Uvoznik.AutoID);
            cmd.Parameters.AddWithValue("@OvlascenoLice", lice.DodatnoOvlascenoLice);
            cmd.CommandTimeout = 60;
            created            = cmd.ExecuteNonQuery() > 0 ? true : false;
            connection.Close();

            return(created);
        }
        public ActionResult SaveEdit(OvlascenaLicaModel ovlascenoLicaModel)
        {
            try
            {
                if (HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik") == null)
                {
                    return(View("~/Views/Login/Index.cshtml"));
                }
                ovlascenoLicaModel.AutoID = Convert.ToInt32(HttpContext.Session.GetInt32("OvlastenoLiceID"));
                OvlascenaLicaDAO.UpdateAuthorizedPerson(ovlascenoLicaModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Edit)));
            }
        }
        // GET: City/Edit/5
        public ActionResult Edit()
        {
            var lice = new OvlascenaLicaModel();

            try
            {
                lice = OvlascenaLicaDAO.GetAuthorizedPersonById(Convert.ToInt32(HttpContext.Session.GetInt32("OvlastenoLiceID")));
                if (HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik") == null)
                {
                    return(View("~/Views/Login/Index.cshtml"));
                }
            }
            catch (Exception)
            {
            }


            return(View(lice));
        }
        public ActionResult Create(OvlascenaLicaModel ovlascenoLicaModel)
        {
            try
            {
                if (HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik") == null)
                {
                    return(View("~/Views/Login/Index.cshtml"));
                }

                ovlascenoLicaModel.Uvoznik.AutoID = Convert.ToInt32(HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik").Uvoznik.AutoID);
                OvlascenaLicaDAO.CreateNewAuthorizedPerson(ovlascenoLicaModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                return(View());
            }
        }