Ejemplo n.º 1
0
        public int updateCost(Batch batch)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();

            Batch existingBatch = getService.getBatchByName(batch.name);

            if (existingBatch.name != null)
            {
                using (SqlCommand command = new SqlCommand("UPDATE ss_stocks SET cost=@cost WHERE bid=" + existingBatch.id + ""))
                {
                    command.Parameters.AddWithValue("@cost", batch.cost);
                    int response = service.execute(command);
                    if (response > 0)
                    {
                        addService.addLog(new Log()
                        {
                            type        = "Updated Cost",
                            statement   = command.CommandText,
                            description = "Updated [" + existingBatch.id + "] Batch",
                        });
                    }
                    return(response);
                }
            }
            else
            {
                return(-404);
            }
        }
Ejemplo n.º 2
0
        public int updatePrice(Product product)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();

            Product existingProduct = getService.getProductByName(product.name);

            if (existingProduct.name != null)
            {
                using (SqlCommand command = new SqlCommand("UPDATE ss_products SET price=@price WHERE id=" + existingProduct.id + ""))
                {
                    command.Parameters.AddWithValue("@price", product.price);
                    int response = service.execute(command);
                    if (response > 0)
                    {
                        addService.addLog(new Log()
                        {
                            type        = "Updated Price",
                            statement   = command.CommandText,
                            description = "Updated [" + existingProduct.id + "] Product",
                        });
                    }
                    return(response);
                }
            }
            else
            {
                return(-404);
            }
        }
Ejemplo n.º 3
0
        public int updateDebtorBalance(Debtor debtor)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();

            Debtor existingDebtor = getService.getDebtorByIdEvenIfZero(debtor.cid);

            if (existingDebtor.name != null)
            {
                using (SqlCommand command = new SqlCommand("UPDATE ss_debtors SET amount=@balance,last_modified_date=getdate() WHERE cid=" + existingDebtor.cid + ""))
                {
                    command.Parameters.AddWithValue("@balance", debtor.amount);
                    int response = service.execute(command);
                    if (response > 0)
                    {
                        addService.addLog(new Log()
                        {
                            type        = "Updated customer debit balance to " + debtor.amount,
                            statement   = command.CommandText,
                            description = "Updated [" + existingDebtor.cid + "] Debit Amount",
                        });
                    }
                    return(response);
                }
            }
            else
            {
                return(-404);
            }
        }
Ejemplo n.º 4
0
        public int updateCustomerBalance(Customer customer)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();

            Customer existingCustomer = getService.getCustomerById(customer.id);

            if (existingCustomer.name != null)
            {
                using (SqlCommand command = new SqlCommand("UPDATE ss_customers SET account_balance=@balance, last_modified_date=getdate() WHERE id=" + existingCustomer.id + ""))
                {
                    command.Parameters.AddWithValue("@balance", customer.account_balance);
                    int response = service.execute(command);
                    if (response > 0)
                    {
                        addService.addLog(new Log()
                        {
                            type        = "Updated customer balance",
                            statement   = command.CommandText,
                            description = "Updated [" + existingCustomer.id + "] Customer",
                        });
                    }
                    return(response);
                }
            }
            else
            {
                return(-404);
            }
        }
Ejemplo n.º 5
0
        public int updateLastLoginDate(User user)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();


            using (SqlCommand command = new SqlCommand("UPDATE ss_users SET login_date=CURRENT_TIMESTAMP WHERE id=" + user.id + ""))
            {
                int response = service.execute(command);
                addService.addLog(new Log()
                {
                    type        = "User logged in",
                    statement   = user.username,
                    description = "User logged in " + user.name,
                });
                return(response);
            }
        }
Ejemplo n.º 6
0
        public int updateBatchBalance(Batch batch)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();

            using (SqlCommand command = new SqlCommand("UPDATE ss_batches SET balance=@balance, sold=@sold WHERE id=" + batch.id + ""))
            {
                command.Parameters.AddWithValue("@balance", batch.balance);
                command.Parameters.AddWithValue("@sold", batch.sold);
                int response = service.execute(command);
                if (response > 0)
                {
                    addService.addLog(new Log()
                    {
                        type        = "Updated batch  balance",
                        statement   = command.CommandText,
                        description = "Updated [" + batch.id + "] Batch",
                    });
                }
                return(response);
            }
        }
Ejemplo n.º 7
0
        public int addBusiness(Business business)
        {
            SSGetService    getService    = new SSGetService();
            SSAddService    addService    = new SSAddService();
            SSRemoteService remoteService = new SSRemoteService();
            SSUpdateService updateService = new SSUpdateService();

            //Business existingBusiness = getService.getBusinessByName(business.business_name);
            //if (existingBusiness.name == null)
            //{

            //    Key key = remoteService.getProductKey(business.product_key);
            //    if (key.product_key != null)
            //    {
            //        if (key.status == "PA")
            //        {
            business.status = "AC";
            //update remote productKet status

            //done

            using (SqlCommand command = new SqlCommand("INSERT INTO ss_business(name,motto,address,telephone,email_address,product_key,machine_name,status,logo)VALUES(@name,@motto,@address,@telephone,@email_address,@product_key,@machine_name,@status,@logo)"))
            {
                command.Parameters.AddWithValue("@name", business.business_name);
                command.Parameters.AddWithValue("@motto", business.motto.ToString().ToUpper());
                command.Parameters.AddWithValue("@address", business.address);
                command.Parameters.AddWithValue("@telephone", business.telephone);
                command.Parameters.AddWithValue("@email_address", business.email_address);
                command.Parameters.AddWithValue("@product_key", business.product_key);
                command.Parameters.AddWithValue("@machine_name", business.machine_name);
                command.Parameters.AddWithValue("@status", business.status);
                if (business.logo != null)
                {
                    command.Parameters.Add("@logo", SqlDbType.Image, business.logo.Length).Value = business.logo;
                }

                int response1 = service.execute(command);
                int response2 = 1;             //service.remoteExecute(command);
                if (response1 > 0 && response2 > 0)
                {
                    Business currentBusiness = getService.getBusinessByName(business.business_name);
                    if (currentBusiness.business_name != null)
                    {
                        //register admin user


                        User user = new User()
                        {
                            bid           = currentBusiness.id,
                            name          = business.name,
                            username      = business.username,
                            password      = business.password,
                            mobile_number = business.telephone,
                            role          = "All",
                        };
                        if (business.logo != null)
                        {
                            user.picture = business.logo;
                        }


                        int res = addService.addUser(user);
                        if (res > 0)
                        {
                            this.addLog(new Log()
                            {
                                type        = "Add Business",
                                statement   = command.CommandText,
                                description = "Added Business" + business.business_name,
                            });
                            return(res);
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else
                {
                    return(-3);
                }
            }
            //        }
            //        else
            //        {
            //            return 201;
            //        }
            //    }
            //    else
            //    {
            //        return -404;
            //    }
            //}
            //else
            //{
            //    return -200;
            //}
        }