public BusinessSuppliersResponse GetAll(long id) { var response = new BusinessSuppliersResponse(); using var db = new salesSystemContext(); var lst = db.BusinessSuppliers .Where(e => e.FkBusinessId == id) .Where(e => !e.FkSupplier.DeletedAt.HasValue) .Select(supplier => new BusinessSupplierItem { Id = supplier.FkSupplier.Id, Email = supplier.FkSupplier.Email, Phone = supplier.FkSupplier.Phone, Name = supplier.FkSupplier.SupplierName, UpdatedAt = supplier.FkSupplier.UpdatedAt }) .ToList(); if (lst.Count == 0) { throw new BusinessExection("No se ha encontrado ningun proveedor asociado a esta empresa"); } response.Count = lst.Count; response.List = lst; response.Total = lst.Count; return(response); }
public IActionResult Get(int business) { var response = new Response(); try { using var db = new salesSystemContext(); var lst = db.BusinessProducts.Where(e => e.FkBusinessId == business).ToList(); if (lst.Count == 0) { throw new BusinessExection("No se ha encontrado ningun producto asociada a esta empresa"); } response.Data = lst; response.Success = true; } catch (BusinessExection exception) { Console.WriteLine(exception); response.Message = exception.Message; } catch (Exception exception) { Console.WriteLine(exception); response.Message = exception.Message; } return(Ok(response)); }
public void Remove(long id) { using var db = new salesSystemContext(); var business = db.Businesses.Find(id); business.DeletedAt = DateTime.Now; db.Entry(business).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Remove(long id) { using var db = new salesSystemContext(); var client = db.Clients.Find(id); client.DeletedAt = DateTime.Now; db.Entry(client).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Update(BusinessUpdateRequest model) { using var db = new salesSystemContext(); var business = db.Businesses.Find(model.Id); business.Address = model.Address; business.BusinessName = model.BusinessName; db.Entry(business).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Create(ClientCreateRequest model) { using var db = new salesSystemContext(); var client = new Models.Client() { ClientName = model.Name }; db.Clients.Add(client); db.SaveChanges(); }
public void Update(ClientUpdateRequest model) { using var db = new salesSystemContext(); var client = db.Clients.Find(model.Id); // product.UpdatedAt = DateTime.Now; client.ClientName = model.Name; client.UpdatedAt = DateTime.Now; db.Entry(client).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Update(SuppliersUpdateRequest model) { using var db = new salesSystemContext(); var supplier = db.Suppliers.Find(model.Id); supplier.Email = model.Email; supplier.SupplierName = model.SupplierName; supplier.Phone = model.Phone; supplier.UpdatedAt = DateTime.Now; db.Entry(supplier).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Create(BusinessCreateRequest model) { using var db = new salesSystemContext(); var business = new Models.Business { Address = model.Address, BusinessName = model.BusinessName, FkUserId = model.FkUserId }; db.Businesses.Add(business); db.SaveChanges(); }
public void Create(ProductCreateRequest model) { using var db = new salesSystemContext(); var product = new Models.Product() { Amount = model.Amount, Description = model.Description, ProductName = model.ProductName, UnitPrice = model.UnitPrice }; db.Products.Add(product); db.SaveChanges(); }
public IActionResult Add(SaleRequest model) { var response = new Response(); try { using var db = new salesSystemContext(); using var transaction = db.Database.BeginTransaction(); try { var sale = new Models.Sale { Total = model.Concepts.Sum(d => d.Amount * d.PriceUnit), CreatedAt = DateTime.Now, FkClientId = model.IdClient }; db.Sales.Add(sale); db.SaveChanges(); foreach (var concept in model.Concepts.Select(rowConcept => new Concept { FkProductId = rowConcept.IdProduct, PriceUnit = rowConcept.PriceUnit, Amount = rowConcept.Amount, Total = rowConcept.Total, FkSaleId = sale.Id })) { db.Concepts.Add(concept); db.SaveChanges(); } response.Success = true; transaction.Commit(); } catch (Exception e) { Console.WriteLine(e); transaction.Rollback(); } } catch (Exception e) { Console.WriteLine(e); response.Message = e.Message; return(BadRequest(response)); } return(Ok(response)); }
public void Create(SuppliersCreateRequest model) { using var db = new salesSystemContext(); var supplier = new Supplier() { Email = model.Email, Phone = model.Phone, SupplierName = model.SupplierName, FkUserId = model.FkUserId }; db.Suppliers.Add(supplier); db.SaveChanges(); }
public void Update(ProductUpdateRequest model) { using var db = new salesSystemContext(); var product = db.Products.Find(model.Id); // product.UpdatedAt = DateTime.Now; product.Amount = model.Amount; product.Description = model.Description; product.ProductName = model.ProductName; product.UnitPrice = model.UnitPrice; product.UpdatedAt = DateTime.Now; db.Entry(product).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public UserResponse?Auth(AuthRequest model) { UserResponse userResponse = new UserResponse(); using var db = new salesSystemContext(); string vpassword = Encrypt.GetSha256(model.Password); User user = db.Users.FirstOrDefault(d => d.Email == model.Email && d.UserPassword == vpassword); if (user == null) { return(null); } userResponse.Email = user.Email; userResponse.Token = GetToken(user); return(userResponse); }
public IActionResult GetAll() { Response response = new Response(); try { using var db = new salesSystemContext(); var lst = db.Clients.ToList(); response.Data = lst; response.Success = true; } catch (Exception exception) { Console.WriteLine(exception); response.Message = exception.Message; } return(Ok(response)); }
public Supplier Get(long id) { using var db = new salesSystemContext(); return(db.Suppliers.FirstOrDefault(e => e.Id == id) !); }
public List <Models.Client> GetAll() { using var db = new salesSystemContext(); return(db.Clients.Where(client => !client.DeletedAt.HasValue).ToList()); }
public Models.Product Get(long id) { using var db = new salesSystemContext(); return(db.Products.FirstOrDefault(e => e.Id == id) !); }
public List <Models.Product> GetAll() { using var db = new salesSystemContext(); return(db.Products.Where(product => !product.DeletedAt.HasValue).ToList()); }
public List <Supplier> GetAll() { using var db = new salesSystemContext(); return(db.Suppliers.Where(supplier => !supplier.DeletedAt.HasValue).ToList()); }