예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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();
                }
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        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();
                }
            }
        }
예제 #7
0
        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();
                }
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
        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);
        }