public bool DeleteOrder(int order_id) { using (var context = new StoreCoreContext()) { var dbOrder = context.inf_order.Find(order_id); if (dbOrder != null) { var product = context.inf_product.FirstOrDefault(f => f.id == dbOrder.product_id && f.record_state != 1); dbOrder.record_updated = DateTime.UtcNow; dbOrder.record_state = 1; context.SaveChanges(); product.count = product.count + dbOrder.count; product.record_state = 2; product.record_updated = DateTime.UtcNow; context.SaveChanges(); return(true); } return(false); } }
public OperationResult AddClient(int type, string name) { var result = OperationResult.CreateWithSuccess(); using (var context = new StoreCoreContext()) { if (!string.IsNullOrEmpty(name)) { var dbClient = context.inf_client.Create(); dbClient.name = name; dbClient.type_id = type; dbClient.creation_date = DateTime.UtcNow; dbClient.record_updated = DateTime.UtcNow; dbClient.record_state = 0; context.inf_client.Add(dbClient); context.SaveChanges(); result.Data.Add("id", dbClient.id); } else { return(OperationResult.CreateWithError("Name is null")); } } return(result); }
public OperationResult AddOrder(Model.Order.Order order) { var result = OperationResult.CreateWithSuccess(); using (var context = new StoreCoreContext()) { var client = context.inf_client.FirstOrDefault(f => f.id == order.ClientId && f.record_state != 1); var product = context.inf_product.FirstOrDefault(f => f.id == order.ProductId && f.record_state != 1); if (client == null) { return(OperationResult.CreateWithError("Client ID is invalid!")); } if (product == null) { return(OperationResult.CreateWithError("Product ID is invalid!")); } if (product.count < order.Count) { return(OperationResult.CreateWithError("Your order amount is not available!")); } if (order != null) { var dbOrder = context.inf_order.Create(); dbOrder.client_id = order.ClientId; dbOrder.product_id = order.ProductId; dbOrder.count = order.Count; dbOrder.amount = product.price; dbOrder.creation_date = DateTime.UtcNow; dbOrder.record_updated = DateTime.UtcNow; dbOrder.record_state = 0; context.inf_order.Add(dbOrder); context.SaveChanges(); product.count = product.count - order.Count; product.record_state = 2; product.record_updated = DateTime.UtcNow; context.SaveChanges(); } else { return(OperationResult.CreateWithError("Error")); } } return(result); }
public OperationResult AddPhysicalEntity(PhysicalEntity client) { var result = OperationResult.CreateWithSuccess(); using (var context = new StoreCoreContext()) { var newEntity = context.inf_physical_entity.FirstOrDefault(f => f.client_id == client.ClientId && f.record_state != 1); if (newEntity != null) { return(OperationResult.CreateWithError("Account is exist!")); } else { var address = context.inf_address.FirstOrDefault(f => f.client_id == client.ClientId && f.record_state != 1); if (address != null) { return(OperationResult.CreateWithError("Address is exist!")); } var dbAddress = context.inf_address.Create(); dbAddress.client_id = client.ClientId; dbAddress.country = client.Address.Country; dbAddress.city = client.Address.City; dbAddress.street = client.Address.Street; dbAddress.home_number = client.Address.HomeNumber; dbAddress.creation_date = DateTime.UtcNow; dbAddress.record_updated = DateTime.UtcNow; dbAddress.record_state = 0; context.inf_address.Add(dbAddress); context.SaveChanges(); var dbClient = context.inf_physical_entity.Create(); dbClient.client_id = client.ClientId; dbClient.date_of_birth = client.DateOfBirth; dbClient.passport_number = client.PassportNumber; dbClient.address = dbAddress.id; dbClient.creation_date = DateTime.UtcNow; dbClient.record_updated = DateTime.UtcNow; dbClient.record_state = 0; context.inf_physical_entity.Add(dbClient); context.SaveChanges(); } } return(result); }
public IEnumerable <Model.Client.Client> GetAllClients() { using (var context = new StoreCoreContext()) { return(context.inf_client.Where(w => w.record_state != 1) .Select(s => new Model.Client.Client { ClientId = s.id, Name = s.name, Type = s.inf_type.name }).ToList()); } }
public int ClientType(int client_id) { using (var context = new StoreCoreContext()) { var res = context.inf_client.FirstOrDefault(f => f.id == client_id && f.record_state != 1); if (res == null) { return(0); } return(res.type_id); } }
public void Delete(int client_id) { using (var context = new StoreCoreContext()) { var dbClient = context.inf_client.FirstOrDefault(f => f.id == client_id && f.record_state != 1); var dbAddress = context.inf_address.FirstOrDefault(f => f.client_id == client_id && f.record_state != 1); if (dbClient.type_id == 1) { var dbFacility = context.inf_legal_entity.FirstOrDefault(f => f.client_id == client_id && f.record_state != 1); if (dbFacility != null) { dbFacility.record_state = 1; dbFacility.record_updated = DateTime.UtcNow; context.SaveChanges(); } } if (dbClient.type_id == 2) { var dbPhysical = context.inf_physical_entity.FirstOrDefault(f => f.client_id == client_id && f.record_state != 1); if (dbPhysical != null) { dbPhysical.record_state = 1; dbPhysical.record_updated = DateTime.UtcNow; context.SaveChanges(); } } if (dbClient != null) { dbClient.record_state = 1; dbClient.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbAddress != null) { dbAddress.record_state = 1; dbAddress.record_updated = DateTime.UtcNow; context.SaveChanges(); } } }
public Model.Product.Product GetProduct(int product_id) { using (var context = new StoreCoreContext()) { return(context.inf_product.Where(w => w.id == product_id && w.record_state != 1) .Select(s => new Model.Product.Product { Id = s.id, Name = s.name, Count = s.count, Price = s.price, CreationDate = s.creation_date }).FirstOrDefault()); } }
public Model.Order.Order GetOrder(int order_id) { using (var context = new StoreCoreContext()) { return(context.inf_order.Where(w => w.id == order_id && w.record_state != 1) .Select(s => new Model.Order.Order { Id = s.id, Client = s.inf_client.name, ClientId = s.client_id, ProductId = s.product_id, Amount = s.amount, Count = s.count }).FirstOrDefault()); } }
public IEnumerable <Model.Product.Product> GetProducts() { using (var context = new StoreCoreContext()) { return(context.inf_product.Where(w => w.record_state != 1) .OrderByDescending(o => o.creation_date) .Select(s => new Model.Product.Product { Id = s.id, Name = s.name, Count = s.count, Price = s.price, CreationDate = s.creation_date }).ToList()); } }
public IEnumerable <Model.Order.Order> GetOrders() { using (var context = new StoreCoreContext()) { return(context.inf_order.Where(w => w.record_state != 1) .OrderByDescending(o => o.creation_date) .Select(s => new Model.Order.Order { Id = s.id, Client = s.inf_client.name, Product = s.inf_product.name, Amount = s.amount, Count = s.count, CreationDate = s.creation_date }).ToList()); } }
public bool DeleteProduct(int product_id) { using (var context = new StoreCoreContext()) { var dbProduct = context.inf_product.Find(product_id); if (dbProduct != null) { dbProduct.record_updated = DateTime.UtcNow; dbProduct.record_state = 1; context.SaveChanges(); return(true); } return(false); } }
public bool UpdateProduct(Model.Product.Product product) { using (var context = new StoreCoreContext()) { var dbProduct = context.inf_product.Find(product.Id); if (dbProduct != null) { dbProduct.name = product.Name; dbProduct.count = product.Count; dbProduct.price = product.Price; dbProduct.record_updated = DateTime.UtcNow; dbProduct.record_state = 2; context.SaveChanges(); return(true); } return(false); } }
public LegalEntity GetLegalClient(int client_id) { using (var context = new StoreCoreContext()) { return(context.inf_legal_entity.Where(w => w.client_id == client_id && w.record_state != 1) .Select(s => new LegalEntity { ClientId = s.client_id, Name = s.inf_client.name, Type = s.inf_client.inf_type.name, TIN = s.tin, Address = new Address() { City = s.inf_address.city, Country = s.inf_address.country, Street = s.inf_address.street, HomeNumber = s.inf_address.home_number } }).FirstOrDefault()); } }
public void UpdatePhysicalClient(PhysicalEntity client) { using (var context = new StoreCoreContext()) { var dbClient = context.inf_client.FirstOrDefault(f => f.id == client.ClientId && f.record_state != 1); var dbAddress = context.inf_address.FirstOrDefault(f => f.client_id == client.ClientId && f.record_state != 1); var dbPhysicalItem = context.inf_physical_entity.FirstOrDefault(f => f.client_id == client.ClientId && f.record_state != 1); if (dbPhysicalItem != null) { dbPhysicalItem.passport_number = client.PassportNumber; dbPhysicalItem.date_of_birth = client.DateOfBirth; dbPhysicalItem.record_state = 2; dbPhysicalItem.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbClient != null) { dbClient.name = client.Name; dbClient.record_state = 2; dbClient.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbAddress != null) { dbAddress.country = client.Address.Country; dbAddress.city = client.Address.City; dbAddress.street = client.Address.Street; dbAddress.home_number = client.Address.HomeNumber; dbAddress.record_state = 2; dbAddress.record_updated = DateTime.UtcNow; context.SaveChanges(); } } }
public PhysicalEntity GetPhysicalClient(int client_id) { using (var context = new StoreCoreContext()) { return(context.inf_physical_entity.Where(w => w.client_id == client_id && w.record_state != 1) .Select(s => new PhysicalEntity { ClientId = s.client_id, Name = s.inf_client.name, Type = s.inf_client.inf_type.name, DateOfBirth = s.date_of_birth, PassportNumber = s.passport_number, Address = new Address() { City = s.inf_address.city, Country = s.inf_address.country, Street = s.inf_address.street, HomeNumber = s.inf_address.home_number } }).FirstOrDefault()); } }
public void UpdateLegalClient(LegalEntity client) { using (var context = new StoreCoreContext()) { var dbClient = context.inf_client.FirstOrDefault(f => f.id == client.ClientId && f.record_state != 1); var dbAddress = context.inf_address.FirstOrDefault(f => f.client_id == client.ClientId && f.record_state != 1); var dbFacility = context.inf_legal_entity.FirstOrDefault(f => f.client_id == client.ClientId && f.record_state != 1); if (dbFacility != null) { dbFacility.tin = client.TIN; dbFacility.record_state = 2; dbFacility.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbClient != null) { dbClient.name = client.Name; dbClient.record_state = 2; dbClient.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbAddress != null) { dbAddress.country = client.Address.Country; dbAddress.city = client.Address.City; dbAddress.street = client.Address.Street; dbAddress.home_number = client.Address.HomeNumber; dbAddress.record_state = 2; dbAddress.record_updated = DateTime.UtcNow; context.SaveChanges(); } } }
public IEnumerable <LegalEntity> GetAllLegalClients() { using (var context = new StoreCoreContext()) { return(context.inf_legal_entity.Where(w => w.record_state != 1) .OrderByDescending(o => o.creation_date) .Select(s => new LegalEntity { ClientId = s.client_id, Name = s.inf_client.name, Type = s.inf_client.inf_type.name, TIN = s.tin, Address = new Address() { City = s.inf_address.city, Country = s.inf_address.country, Street = s.inf_address.street, HomeNumber = s.inf_address.home_number }, CreationDate = s.creation_date }).ToList()); } }
public bool AddProduct(Model.Product.Product product) { using (var context = new StoreCoreContext()) { if (product != null) { var dbProduct = context.inf_product.Create(); dbProduct.name = product.Name; dbProduct.count = product.Count; dbProduct.price = product.Price; dbProduct.creation_date = DateTime.UtcNow; dbProduct.record_updated = DateTime.UtcNow; dbProduct.record_state = 0; context.inf_product.Add(dbProduct); context.SaveChanges(); return(true); } return(false); } }
public IEnumerable <PhysicalEntity> GetAllPhysicalClients() { using (var context = new StoreCoreContext()) { return(context.inf_physical_entity.Where(w => w.record_state != 1) .OrderByDescending(o => o.creation_date) .Select(s => new PhysicalEntity { ClientId = s.client_id, Name = s.inf_client.name, Type = s.inf_client.inf_type.name, DateOfBirth = s.date_of_birth, PassportNumber = s.passport_number, Address = new Address() { City = s.inf_address.city, Country = s.inf_address.country, Street = s.inf_address.street, HomeNumber = s.inf_address.home_number }, CreationDate = s.creation_date }).ToList()); } }
public OperationResult UpdateOrder(Model.Order.Order order) { var result = OperationResult.CreateWithSuccess(); using (var context = new StoreCoreContext()) { var dbProduct = context.inf_product.FirstOrDefault(f => f.id == order.ProductId && f.record_state != 1); var dbOrder = context.inf_order.FirstOrDefault(f => f.id == order.Id && f.record_state != 1); if (dbProduct == null) { return(OperationResult.CreateWithError("Product ID is invalid!")); } if (dbProduct.count < order.Count) { return(OperationResult.CreateWithError("Your order amount is not available!")); } if (dbOrder != null) { var productId = dbOrder.product_id; var prodAmount = dbOrder.count; dbOrder.product_id = order.ProductId; dbOrder.count = order.Count; dbOrder.amount = dbProduct.price; dbOrder.record_updated = DateTime.UtcNow; dbOrder.record_state = 2; context.SaveChanges(); if (prodAmount < order.Count) { var res = order.Count - prodAmount; dbProduct.count = dbProduct.count - res; dbProduct.record_state = 2; dbProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (prodAmount > order.Count) { var res1 = prodAmount - order.Count; dbProduct.count = dbProduct.count + res1; dbProduct.record_state = 2; dbProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbOrder.product_id != productId) { var dbOldProduct = context.inf_product.FirstOrDefault(f => f.id == productId & f.record_state != 1); if (dbOldProduct != null) { dbOldProduct.count = dbOldProduct.count + prodAmount; dbOldProduct.record_state = 2; dbOldProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); dbProduct.count = dbProduct.count - prodAmount; dbProduct.record_state = 2; dbProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); } } } else { return(OperationResult.CreateWithError("Error")); } } return(result); }