コード例 #1
0
        public ActionResult Edit(int id, Alquiler alquiler)
        {
            //var miPropietario = repositorio.ObtenerPorId(id);

            if (id != alquiler.AlquilerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    repositorio.Modificacion(alquiler);
                }
                catch (Exception ex)
                {
                    ViewBag.Error      = ex.Message;
                    ViewBag.StackTrate = ex.StackTrace;
                    return(View());
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
コード例 #2
0
 public ActionResult Create(Alquiler alquiler)
 {
     try
     {
         return(View());
     }
     catch (Exception ex)
     {
         ViewBag.Error      = ex.Message;
         ViewBag.StackTrate = ex.StackTrace;
         return(View());
     }
 }
コード例 #3
0
        public int Alta(Alquiler entidad)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Alquileres ( Descripcion,FechaAlta , FechaBaja , Monto , InmuebleId , InquilinoId) " +
                             $"VALUES ('{entidad.Descripcion}','{entidad.FechaAlta}', '{entidad.FechaBaja}','{entidad.Monto}','{entidad.InmuebleId}','{entidad.InquilinoId}')";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    command.CommandText = "SELECT SCOPE_IDENTITY()";
                    var id = command.ExecuteScalar();
                    entidad.AlquilerId = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }