Avançar para o conteúdo principal

Mensagens

A mostrar mensagens de fevereiro, 2018

ASP.NET MVC with Entity, Identity and Migrations Part 3 - File Upload

In the third part of this MVC tutorial we add two new controllers and models with the ability to upload files to our web site. The Room model is pretty simple:  public class Room {         [Key]         public int nr { get; set; }         [Required(ErrorMessage = "Deve indicar o piso do quarto")]         public int piso { get; set; }         [Required(ErrorMessage = "Deve indicar a lotação")]         public int lotacao { get; set; }         [Required(ErrorMessage = "Deve indicar o estado do quarto")]         public bool estado { get; set; }         [DataType(DataType.Currency)]         [Required(ErrorMessage = "Deve indicar o preço por dia do quarto")]         public decimal custo_dia { get; set; }     } Just add the controller with Entity framework and that's it. Next add the Client model:     public class Client {         [Key]         public int ClientId { get; set; }         [Required(ErrorMessage = "Tem

TensorFlow Variables and Placeholders

In this second part of the introduction to TensorFlow we add two new node types: variables and placeholders. Let's use the same example that we have used in the first part. We start by importing TensorFlow: import tensorflow as tf Next we start a session, but before let's make a reset to the graph internal state: tf.reset_default_graph() sess=tf.Session() And now we create two variables of type 32 bit float: x = tf.Variable(2.0,tf.float32) y = tf.Variable(3.0,tf.float32) Since we are using variables we must initialize them: init = tf.global_variables_initializer() sess.run(init) The mathematical expression is this: sumnodes = x + y To evaluate the expression: print(sess.run(sumnodes)) Because we are using variables we can change the values like so: sess.run(x.assign(5.0)) As always we must execute the assign operation inside a TF session. To make multiple assigns we create references to the operations and execu

Introduction to TensorFlow - Part 1

"TensorFlow is an open source software library for numerical computation" in tensorflow.org In TensorFlow each node can be a constant, a variable or a numerical expression that uses variables and/or constants. This nodes can be executed in a CPU or a GPU taking advantage of multicore devices. Start by import the tensorflow library: import tensorflow as tf Create a constant with: node1 = tf.constant(3.0) or node2 = tf.constant(4.0, dtype=tf.float32) The first line allows tensorflow to guess the data type. Start a tensorflow session: sess = tf.Session() If you need to see the node type use: print(node1,node2) With this line you get to evaluate the nodes value: print(sess.run([node1,node2])) Create a mathematical function that adds the two constants with: sumnodes = tf.add(node1,node2) Evaluate the function: print(sess.run(sumnodes)) Youtube video: Code on GiHub How to install TensorFlow in Anaconda:

ASP.NET MVC with Entity, Identity and Migrations Part 2 - Dropdownlist

In the second part of this MVC tutorial we add a dropdown list to select the user role when creating or editing a user. In the User model we must add a new field that represents an interface that stores the options: public IEnumerable<System.Web.Mvc.SelectListItem> perfis { get; set; } Now in the User controller the Create and Edit functions must be changed. Each function must add the options to the perfis interface before showing the view. Something like this:         // GET: Users/Create         public ActionResult Create()         {             //perfis options for the dropdownlist             var user = new User();             user.perfis = new[] {                 new SelectListItem{Value="0",Text="Admin"},                 new SelectListItem{Value="1",Text="User"},             };             return View(user);         } In the views the text box must be deleted and a drop down must be added to the field. The line

ASP.NET MVC with Entity, Identity and Migrations

In this tutorial we explore the Microsoft MVC architecture with Entity framework, Identity framework and Migrations for the database manipulation. Entity framework is responsible for Object-Relational Mapping, i.e., storing objects in a relational SQL Server database, without SQL. Identity framework controls the user credentials, login and access control with different roles for each user. The database will be created with migrations (code first), we start by creating the class that represents the data in memory and then with migrations the table gets created. Checkout the video bellow The code is available on Github .