Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Mvc.Rendering;
  7. using Microsoft.EntityFrameworkCore;
  8. using WebApplication2.Data;
  9. using WebApplication2.Models;
  10.  
  11. namespace WebApplication2.Controllers
  12. {
  13.     public class BOesController : Controller
  14.     {
  15.         private readonly ApplicationDbContext _context;
  16.  
  17.         public BOesController(ApplicationDbContext context)
  18.         {
  19.             _context = context;
  20.         }
  21.  
  22.         public async Task<IActionResult> Teste()
  23.         {
  24.             var bo = _context.BOs.LastOrDefault();
  25.  
  26.             return Content(bo.BOGCM);
  27.         }
  28.  
  29.         public IActionResult Criar() {
  30.  
  31.             var bo = _context.BOs.Where(w => w.BoAno == DateTime.Today.Year).Max(m => m.BoSequencial) + 1;
  32.  
  33.             var newBO = new BO
  34.             {
  35.                 BOGCM = $"{bo}-{DateTime.Today.Year}"
  36.             };
  37.  
  38.             _context.Add(newBO);
  39.             _context.SaveChanges();
  40.             return Content(newBO.BOGCM);
  41.  
  42.  
  43.  
  44.  
  45.         }
  46.  
  47.         public IActionResult Criar2()
  48.         {
  49.  
  50.             var bo = _context.BOs.LastOrDefault();
  51.  
  52.             var NewNumero = bo.BoSequencial + 1;
  53.             var newBO = new BO
  54.             {
  55.                 BOGCM = $"{NewNumero}-{DateTime.Today.Year}"
  56.             };
  57.  
  58.             _context.Add(newBO);
  59.             _context.SaveChanges();
  60.             return Content(newBO.BOGCM);
  61.  
  62.  
  63.  
  64.  
  65.         }
  66.  
  67.         private bool BOExists(int id)
  68.         {
  69.             return _context.BOs.Any(e => e.BOId == id);
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement