public IHttpActionResult GetVendedorPorId(int idVendedor) { if (idVendedor <= 0) { return(BadRequest("El id del vendedor ingresado es inválido")); } VendedorDTO vendedor = null; using (EcommerceDbContext context = new EcommerceDbContext()) { vendedor = context.Vendedores .Where(v => v.VendedorId == idVendedor) .Select(v => new VendedorDTO() { VendedorId = v.VendedorId, Nombre = v.Nombre, Apellido = v.Apellido, NroDocumento = v.DNI, FechaDeNacimiento = v.FechaDeNacimiento, }).FirstOrDefault <VendedorDTO>(); } if (vendedor == null) { return(NotFound()); } return(Ok(vendedor)); }
public IHttpActionResult ActualizarVendedor(VendedorDTO vendedor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { Vendedor vendedorDB = context.Vendedores.Find(vendedor.VendedorId); if (vendedorDB == null) { return(NotFound()); } //Modifico los campos con los datos por parámetro vendedorDB.Nombre = vendedor.Nombre; vendedorDB.Apellido = vendedor.Apellido; vendedorDB.DNI = vendedor.NroDocumento; vendedorDB.FechaDeNacimiento = vendedor.FechaDeNacimiento; context.SaveChanges(); } return(Ok(vendedor.VendedorId)); }
public IHttpActionResult GetAllVendedores() { List <VendedorDTO> vendedores = new List <VendedorDTO>(); using (EcommerceDbContext context = new EcommerceDbContext()) { vendedores = context.Vendedores .Select(v => new VendedorDTO() { VendedorId = v.VendedorId, Nombre = v.Nombre, Apellido = v.Apellido, FechaDeNacimiento = v.FechaDeNacimiento, NroDocumento = v.DNI }) .ToList(); } if (vendedores.Count == 0) { return(NotFound()); } return(Ok(vendedores)); }
public IHttpActionResult CargarProducto(ProductoDTO producto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { //Instanciando un objeto de la clase Producto try { var prodDB = new Producto() { Descripcion = producto.Descripcion, Stock = producto.Stock, CategoriaId = producto.Categoria.CategoriaId, }; context.Productos.Add(prodDB); context.SaveChanges(); producto.CodProducto = prodDB.CodProducto; } catch (Exception e) { return(BadRequest(e.InnerException.InnerException.Message)); } } //Retornar un objeto de la clase ProductoDTO con el id generado return(Ok(producto)); }
public IHttpActionResult GetProductoPorCodigo(int codProducto) { if (codProducto <= 0) { return(BadRequest("El código de producto ingresado es inválido")); } ProductoDTO producto = null; using (EcommerceDbContext context = new EcommerceDbContext()) { producto = context.Productos .Include("Categoria") .Where(p => p.CodProducto == codProducto) .Select(p => new ProductoDTO() { CodProducto = p.CodProducto, Descripcion = p.Descripcion, Precio = p.Precio, Stock = p.Stock, Categoria = p.CategoriaId == null ? null : new CategoriaDTO() { Nombre = p.Categoria.Descripcion, CategoriaId = p.Categoria.CategoriaId } }).FirstOrDefault <ProductoDTO>(); } if (producto == null) { return(NotFound()); } return(Ok(producto)); }
public IHttpActionResult GetAllProductos() { List <ProductoDTO> productos = new List <ProductoDTO>(); using (EcommerceDbContext context = new EcommerceDbContext()) { productos = context.Productos .Include("Categoria") .Select(p => new ProductoDTO() { CodProducto = p.CodProducto, Stock = p.Stock, Descripcion = p.Descripcion, Categoria = p.CategoriaId == null ? null : new CategoriaDTO() { CategoriaId = p.Categoria.CategoriaId, Nombre = p.Categoria.Descripcion } }) .ToList(); } if (productos.Count == 0) { return(NotFound()); } return(Ok(productos)); }
public IHttpActionResult CargarVendedor(VendedorDTO vendedor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { try { var vendedorDB = new Vendedor() { Nombre = vendedor.Nombre, Apellido = vendedor.Apellido, DNI = vendedor.NroDocumento, FechaDeNacimiento = vendedor.FechaDeNacimiento }; context.Vendedores.Add(vendedorDB); context.SaveChanges(); vendedor.VendedorId = vendedorDB.VendedorId; } catch (Exception e) { return(BadRequest(e.InnerException.InnerException.Message)); } } return(Ok(vendedor)); }
public IHttpActionResult CargarVenta(VentaDTO venta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { try { var ventaDB = new Venta() { VendedorId = venta.Vendedor.VendedorId, FechaDeVenta = venta.FechaVenta, }; context.Ventas.Add(ventaDB); context.SaveChanges(); venta.VentaId = ventaDB.VentaId; } catch (Exception e) { return(BadRequest(e.InnerException.InnerException.Message)); } } return(Ok(venta)); }
public IHttpActionResult CargarCategoria(CategoriaDTO categoria) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { //Instanciando un objeto de la clase categoria try { var catDB = new Categoria() { Descripcion = categoria.Nombre }; context.Categorias.Add(catDB); context.SaveChanges(); //Guardar el id de la categoria registrada categoria.CategoriaId = catDB.CategoriaId; } catch (Exception e) { return(BadRequest(e.InnerException.InnerException.Message)); } } return(Ok(categoria)); }
private void CreateContactDetail(EcommerceDbContext context) { if (context.ContactDetails.Count() == 0) { try { var contactDetail = new Ecommerce.Model.Models.ContactDetail() { Name = "Shop thời trang TEDU", Address = "Ngõ 77 Xuân La", Email = "*****@*****.**", Lat = 21.0633645, Lng = 105.8053274, Phone = "095423233", Website = "http://tedu.com.vn", Other = "", Status = true }; context.ContactDetails.Add(contactDetail); context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error."); foreach (var ve in eve.ValidationErrors) { Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""); } } } } }
public FileResult Export() { EcommerceDbContext entities = new EcommerceDbContext(); DataTable dt = new DataTable("Grid"); dt.Columns.AddRange(new DataColumn[5] { new DataColumn("STT"), new DataColumn("Người nhận hàng"), new DataColumn("Điện thoại"), new DataColumn("Địa chỉ"), new DataColumn("Email") }); var customers = from customer in entities.Orders.Take(10) select customer; foreach (var customer in customers) { dt.Rows.Add(customer.ID, customer.ShipName, customer.ShipMobile, customer.ShipAddress, customer.ShipEmail); } using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); using (MemoryStream stream = new MemoryStream()) { wb.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Doanh thu.xlsx")); } } }
public IHttpActionResult GetAllVentas() { var ventas = new List <VentaDTO>(); using (EcommerceDbContext context = new EcommerceDbContext()) { ventas = context.Ventas .Include("Vendedor") .Select(v => new VentaDTO() { VentaId = v.VentaId, FechaVenta = v.FechaDeVenta, Vendedor = new VendedorDTO() { VendedorId = v.Vendedor.VendedorId, Nombre = v.Vendedor.Nombre, Apellido = v.Vendedor.Apellido }, //Falta agregar el detalle de venta con los productos que se vendieron }).ToList <VentaDTO>(); } if (ventas.Count == 0) { return(NotFound()); } return(Ok(ventas)); }
private void CreatePage(EcommerceDbContext context) { if (context.Pages.Count() == 0) { try { var page = new Page() { Name = "Giới thiệu", Alias = "gioi-thieu", Content = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium ", Status = true }; context.Pages.Add(page); context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error."); foreach (var ve in eve.ValidationErrors) { Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""); } } } } }
public IHttpActionResult GetVentaPorId(int idVenta) { if (idVenta <= 0) { return(BadRequest("El id de la venta ingresado es inválido")); } VentaDTO venta = null; using (EcommerceDbContext context = new EcommerceDbContext()) { venta = context.Ventas .Include("Vendedor") .Where(v => v.VentaId == idVenta) .Select(v => new VentaDTO() { VentaId = v.VentaId, FechaVenta = v.FechaDeVenta, Vendedor = new VendedorDTO() { VendedorId = v.Vendedor.VendedorId, Nombre = v.Vendedor.Nombre, Apellido = v.Vendedor.Apellido }, }).FirstOrDefault <VentaDTO>(); } if (venta == null) { return(NotFound()); } return(Ok(venta)); }
private void CreateConfigTitle(EcommerceDbContext context) { if (!context.SystemConfigs.Any(x => x.Code == "HomeTitle")) { context.SystemConfigs.Add(new SystemConfig() { Code = "HomeTitle", ValueString = "Trang chủ Ecommerce", }); } if (!context.SystemConfigs.Any(x => x.Code == "HomeMetaKeyword")) { context.SystemConfigs.Add(new SystemConfig() { Code = "HomeMetaKeyword", ValueString = "Trang chủ Ecommerce", }); } if (!context.SystemConfigs.Any(x => x.Code == "HomeMetaDescription")) { context.SystemConfigs.Add(new SystemConfig() { Code = "HomeMetaDescription", ValueString = "Trang chủ Ecommerce", }); } }
public IHttpActionResult ActualizarProducto(ProductoDTO producto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { Producto prodDB = context.Productos.Find(producto.CodProducto); if (prodDB == null) { return(NotFound()); } //Modifico los campos con los datos por parámetro prodDB.Descripcion = producto.Descripcion; prodDB.Stock = producto.Stock; prodDB.Precio = producto.Precio; prodDB.CategoriaId = producto.Categoria.CategoriaId; context.SaveChanges(); } return(Ok(producto.CodProducto)); }
public IHttpActionResult ActualizarVenta(VentaDTO venta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new EcommerceDbContext()) { Venta ventaDB = context.Ventas.Find(venta.VentaId); if (ventaDB == null) { return(NotFound()); } //Modifico los campos con los datos por parámetro ventaDB.VendedorId = venta.Vendedor.VendedorId; ventaDB.FechaDeVenta = venta.FechaVenta; context.SaveChanges(); } return(Ok(venta.VentaId)); }
public bool RegisterAccount(Account account, out string message) { message = string.Empty; if (FindAccount(account) != null) { throw new Exception("Email is not valid, choose another email"); } var newAccountRegister = new Account(); newAccountRegister.AccountId = 0; newAccountRegister.EmailLogin = account.EmailLogin; newAccountRegister.PassWordSalt = DateTime.UtcNow.ToString().EncriptString(); newAccountRegister.Password = account.Password.EncriptString() + newAccountRegister.PassWordSalt; newAccountRegister.CreatedDate = DateTime.Now; newAccountRegister.AccountRoleId = account.AccountRoleId; newAccountRegister.AccountStatusID = account.AccountStatusID; using (var dbContext = new EcommerceDbContext()) { dbContext.Accounts.Add(newAccountRegister); newAccountRegister.AccountId = dbContext.SaveChanges(); } return(true); }
private IEnumerable <Contact> GetContactsByEmail(string email) { using (var dbContext = new EcommerceDbContext()) { return(dbContext.Contacts.Where(c => c.ContactEmail == email).ToList()); } }
/// <summary> /// Identity Instance constructor /// </summary> /// <param name="context">Ecommerce Db Context</param> /// <param name="userManager">Application User Manager </param> /// <param name="roleManager">Role Manager</param> /// <param name="jwtSettings">Jwt settings</param> /// <param name="tokenValidationParameters">Token Validator Parameters</param> public IdentityRepository(EcommerceDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager , JwtSettings jwtSettings, TokenValidationParameters tokenValidationParameters) { _userManager = userManager; _roleManager = roleManager; _context = context; _jwtSettings = jwtSettings; _tokenValidationParameters = tokenValidationParameters; }
static void ShowAllProducts() { EcommerceDbContext db = new EcommerceDbContext(); var products = db.Products.ToList(); foreach (var product in products) { Console.WriteLine(product.Id + " " + product.Name + " " + product.Price + " " + product.ExpireDate.Value.ToShortDateString()); } }
private static List <Allcode> GetAll() { var allCodes = new List <Allcode>(); using (var context = new EcommerceDbContext()) { allCodes = context.Allcodes.Select(x => x).ToList(); } return(allCodes); }
public List <Product> GetProductByExpression(Expression <Func <Product, bool> > expression) { List <Product> products = new List <Product>(); using (var context = new EcommerceDbContext()) { products = context.Products.Where(expression.Compile()).ToList(); } return(products); }
public Product GetProductById(int productId) { Product product = new Product(); using (var context = new EcommerceDbContext()) { product = context.Products.Find(productId); } return(product?.ProductStatusId != (int)ProductEnum.Status.Deleted ? product : new Product()); }
public GioHang(Guid productCode) { using (EcommerceDbContext db = new EcommerceDbContext()) { this.ProductCode = productCode; Product product = db.Products.Single(s => s.Id == productCode); this.ProductName = product.Name; this.ProductPrice = product.Price; this.ProductImage = product.UrlImage; this.TotalPrice = product.productInStock * product.Price; } }
public Product InsertProduct(Product product) { int totalChanges = 0; using (var context = new EcommerceDbContext()) { context.Products.Add(product); totalChanges = context.SaveChanges(); } return(product); }
public ItemGioHang(int productCode, int quantityProduct) { using (EcommerceDbContext db = new EcommerceDbContext()) { this.ProductCode = productCode; Product product = db.Products.Single(s => s.Id == productCode); this.ProductName = product.Name; this.QuantityProduct = quantityProduct; this.ProductPrice = product.Price; this.ProductImage = product.UrlImage; this.TotalPrice = product.ProductInStock * product.Price; } }
private void CreateFooter(EcommerceDbContext context) { if (context.Footers.Count(x => x.ID == CommonConstants.DefaultFooterId) == 0) { string content = "Footer"; context.Footers.Add(new Footer() { ID = CommonConstants.DefaultFooterId, Content = content }); context.SaveChanges(); } }
public int UpdateProduct(Product product) { int totalChanges = 0; using (var context = new EcommerceDbContext()) { context.Products.Attach(product); context.Entry(product).State = EntityState.Modified; totalChanges = context.SaveChanges(); } return(totalChanges); }
public Account FindAccount(Account account) { var accountResult = new Account(); if (account.AccountId != 0 || !string.IsNullOrEmpty(account.EmailLogin)) { using (var dbContext = new EcommerceDbContext()) { accountResult = dbContext.Accounts.Where(a => a.EmailLogin == account.EmailLogin).FirstOrDefault(); } } else { return(null); } return(accountResult); }