diff --git a/Data/Context/SystemContext.cs b/Data/Context/SystemContext.cs index dc1a84c..81f1fec 100644 --- a/Data/Context/SystemContext.cs +++ b/Data/Context/SystemContext.cs @@ -26,5 +26,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder) base.OnModelCreating(modelBuilder); } + + } } diff --git a/Data/Migrations/Configuration.cs b/Data/Migrations/Configuration.cs index e2521e0..05aa989 100644 --- a/Data/Migrations/Configuration.cs +++ b/Data/Migrations/Configuration.cs @@ -14,7 +14,11 @@ public Configuration() protected override void Seed(Data.Context.SystemContext context) { - + //context.Authors.AddOrUpdate(x => x.Id, + // new Author() { Id = 1, Name = "Jane Austen" }, + // new Author() { Id = 2, Name = "Charles Dickens" }, + // new Author() { Id = 3, Name = "Miguel de Cervantes" } + // ); } } } diff --git a/WebAPI/App_Start/WebApiConfig.cs b/WebAPI/App_Start/WebApiConfig.cs index 5cb6c51..23488ee 100644 --- a/WebAPI/App_Start/WebApiConfig.cs +++ b/WebAPI/App_Start/WebApiConfig.cs @@ -17,7 +17,7 @@ public static void Register(HttpConfiguration config) config.Routes.MapHttpRoute( name: "DefaultApi", - routeTemplate: "{controller}/{id}", + routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } diff --git a/WebAPI/Controllers/NotaFiscalsController.cs b/WebAPI/Controllers/NotaFiscalsController.cs new file mode 100644 index 0000000..020ae5f --- /dev/null +++ b/WebAPI/Controllers/NotaFiscalsController.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Entity; +using System.Data.Entity.Infrastructure; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; +using System.Web.Http.Description; +using WebAPI.Models; + +namespace WebAPI.Controllers +{ + public class NotaFiscalsController : ApiController + { + private WebAPIContext db = new WebAPIContext(); + + // GET: api/NotaFiscals + public IQueryable GetNotaFiscals() + { + return db.NotaFiscals; + } + + // GET: api/NotaFiscals/5 + [ResponseType(typeof(NotaFiscal))] + public IHttpActionResult GetNotaFiscal(int id) + { + NotaFiscal notaFiscal = (NotaFiscal)db.NotaFiscals.Find(id); + if (notaFiscal == null) + { + return NotFound(); + } + + return Ok(notaFiscal); + } + + // PUT: api/NotaFiscals/5 + [ResponseType(typeof(void))] + public IHttpActionResult PutNotaFiscal(int id, NotaFiscal notaFiscal) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + if (id != notaFiscal.NotaFiscalId) + { + return BadRequest(); + } + + db.Entry(notaFiscal).State = EntityState.Modified; + + try + { + db.SaveChanges(); + } + catch (DbUpdateConcurrencyException) + { + if (!NotaFiscalExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return StatusCode(HttpStatusCode.NoContent); + } + + // POST: api/NotaFiscals + [ResponseType(typeof(NotaFiscal))] + public IHttpActionResult PostNotaFiscal(NotaFiscal notaFiscal) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + db.NotaFiscals.Add(notaFiscal); + db.SaveChanges(); + + return CreatedAtRoute("DefaultApi", new { id = notaFiscal.NotaFiscalId }, notaFiscal); + } + + // DELETE: api/NotaFiscals/5 + [ResponseType(typeof(NotaFiscal))] + public IHttpActionResult DeleteNotaFiscal(int id) + { + NotaFiscal notaFiscal = (NotaFiscal)db.NotaFiscals.Find(id); + if (notaFiscal == null) + { + return NotFound(); + } + + db.NotaFiscals.Remove(notaFiscal); + db.SaveChanges(); + + return Ok(notaFiscal); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + + private bool NotaFiscalExists(int id) + { + return db.NotaFiscals.Count(e => e.NotaFiscalId == id) > 0; + } + } +} \ No newline at end of file diff --git a/WebAPI/Migrations/201808111535064_Initial.Designer.cs b/WebAPI/Migrations/201808111535064_Initial.Designer.cs new file mode 100644 index 0000000..86a5249 --- /dev/null +++ b/WebAPI/Migrations/201808111535064_Initial.Designer.cs @@ -0,0 +1,29 @@ +// +namespace WebAPI.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")] + public sealed partial class Initial : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(Initial)); + + string IMigrationMetadata.Id + { + get { return "201808111535064_Initial"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/WebAPI/Migrations/201808111535064_Initial.cs b/WebAPI/Migrations/201808111535064_Initial.cs new file mode 100644 index 0000000..6e356e3 --- /dev/null +++ b/WebAPI/Migrations/201808111535064_Initial.cs @@ -0,0 +1,30 @@ +namespace WebAPI.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class Initial : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.NotaFiscals", + c => new + { + NotaFiscalId = c.Int(nullable: false, identity: true), + NumeroNF = c.String(), + ValorTotal = c.Double(nullable: false), + DataNF = c.DateTime(nullable: false), + CNPJEmissorNF = c.String(), + CNPJDestinatarioNF = c.String(), + }) + .PrimaryKey(t => t.NotaFiscalId); + + } + + public override void Down() + { + DropTable("dbo.NotaFiscals"); + } + } +} diff --git a/WebAPI/Migrations/201808111535064_Initial.resx b/WebAPI/Migrations/201808111535064_Initial.resx new file mode 100644 index 0000000..5538723 --- /dev/null +++ b/WebAPI/Migrations/201808111535064_Initial.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAM1YyY7jNhC9B8g/CDolQI/ZyyVpyDPo2O3AydhtjDyTMy2V3US4K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YRAF2Z3h5ZXzSVdwItL+yRhhAtmqgXA/ICUkrpMb0MpmLJequgOMsc2oMvGuaAKWYsXQB23ZkiYWtxMwZjtYYn3maPIoFpCO5VNus9w+GANiwXd+HUTkuP/tELbLOXrK3JN5ixCQJnNF/yR/yRlPa96jbtEfgnBVU6oEssLBGuFWmxppquSZQGX6hpCBdBozB5FxBDNPMqYv8BpuOFF/hBVNNtV74zDI6YvYTXs0ZHSlqTAlRnPe/Q1C3P8g7/8DBFmlPjkRAAA= + + + dbo + + \ No newline at end of file diff --git a/WebAPI/Migrations/Configuration.cs b/WebAPI/Migrations/Configuration.cs new file mode 100644 index 0000000..d95f0c8 --- /dev/null +++ b/WebAPI/Migrations/Configuration.cs @@ -0,0 +1,25 @@ +namespace WebAPI.Migrations +{ + using System; + using System.Data.Entity; + using System.Data.Entity.Migrations; + using System.Linq; + using WebAPI.Models; + + internal sealed class Configuration : DbMigrationsConfiguration + { + public Configuration() + { + AutomaticMigrationsEnabled = false; + } + + protected override void Seed(WebAPI.Models.WebAPIContext context) + { + context.NotaFiscals.AddOrUpdate(x => x.NotaFiscalId, + new NotaFiscal() { NotaFiscalId = 1, CNPJDestinatarioNF = "57.877.625/0001-53", CNPJEmissorNF = "21.709.451/0001-72", DataNF = DateTime.Now, NumeroNF = "1000", ValorTotal = 2500.45 }, + new NotaFiscal() { NotaFiscalId = 2, CNPJDestinatarioNF = "48.792.344/0001-07", CNPJEmissorNF = "17.710.632/0001-41", DataNF = DateTime.Now, NumeroNF = "2000", ValorTotal = 7500.22 }, + new NotaFiscal() { NotaFiscalId = 3, CNPJDestinatarioNF = "24.886.518/0001-32", CNPJEmissorNF = "41.578.027/0001-43", DataNF = DateTime.Now, NumeroNF = "3000", ValorTotal = 1250.00 } + ); + } + } +} diff --git a/WebAPI/Models/NotaFiscal.cs b/WebAPI/Models/NotaFiscal.cs new file mode 100644 index 0000000..bc2a8fa --- /dev/null +++ b/WebAPI/Models/NotaFiscal.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Web; + +namespace WebAPI.Models +{ + public class NotaFiscal + { + [Key] + public int NotaFiscalId { get; set; } + + public string NumeroNF { get; set; } + + public double ValorTotal { get; set; } + + public DateTime DataNF { get; set; } + + public string CNPJEmissorNF { get; set; } + + public string CNPJDestinatarioNF { get; set; } + } +} \ No newline at end of file diff --git a/WebAPI/Models/WebAPIContext.cs b/WebAPI/Models/WebAPIContext.cs new file mode 100644 index 0000000..7ee4166 --- /dev/null +++ b/WebAPI/Models/WebAPIContext.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Web; + +namespace WebAPI.Models +{ + public class WebAPIContext : DbContext + { + // You can add custom code to this file. Changes will not be overwritten. + // + // If you want Entity Framework to drop and regenerate your database + // automatically whenever you change your model schema, please use data migrations. + // For more information refer to the documentation: + // http://msdn.microsoft.com/en-us/data/jj591621.aspx + + public WebAPIContext() : base("name=WebAPIContext") + { + } + + public System.Data.Entity.DbSet NotaFiscals { get; set; } + } +} diff --git a/WebAPI/Web.config b/WebAPI/Web.config index 45a29ce..f0fc205 100644 --- a/WebAPI/Web.config +++ b/WebAPI/Web.config @@ -1,4 +1,4 @@ - + + @@ -37,8 +39,6 @@ - - diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj index 8eed6ac..d98da54 100644 --- a/WebAPI/WebAPI.csproj +++ b/WebAPI/WebAPI.csproj @@ -236,9 +236,17 @@ + Global.asax + + + 201808111535064_Initial.cs + + + + @@ -347,9 +355,7 @@ - - @@ -380,6 +386,11 @@ + + + 201808111535064_Initial.cs + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)