public void Post([FromBody] OperationTypeViewModel value)
        {
            OperationTypeItem item = new OperationTypeItem();

            item.Name = value.Name;
            _db.AddOperationTypeItem(item);
        }
        private OperationTypeItem GetOperationTypeItemFromReader(SqlDataReader reader)
        {
            OperationTypeItem item = new OperationTypeItem();

            item.Id   = Convert.ToInt32(reader["Id"]);
            item.Name = Convert.ToString(reader["Name"]);

            return(item);
        }
Пример #3
0
    private void SetOperationTypesStr_LeaveReserve()
    {
        string strOperationTypes = string.Empty;

        foreach (LeaveIncDecAction OperationTypeItem in Enum.GetValues(typeof(LeaveIncDecAction)))
        {
            strOperationTypes += "#" + GetLocalResourceObject(OperationTypeItem.ToString()).ToString() + ":" + ((int)OperationTypeItem).ToString();
        }
        this.hfOperationTypes_LeaveReserve.Value = strOperationTypes;
    }
        public void AddOperationTypeItem(OperationTypeItem item)
        {
            const string sql = "INSERT OperationType (Id, Name) " +
                               "VALUES (@Id, @Name);";

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(sql + _getLastIdSQL, conn);
                cmd.Parameters.AddWithValue("@Id", item.Id);
                cmd.Parameters.AddWithValue("@Name", item.Name);
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        /// Creates each type of vending operation and a purchase operation for each product in the system
        /// </summary>
        /// <param name="db">Database interface used to create the data</param>
        /// <param name="log">Log interface used to create the file data</param>
        public static void PopulateLogFileWithOperations(IVendingService db, ILogService log)
        {
            OperationTypeItem type = new OperationTypeItem();

            type.Id   = (int)VendingOperation.eOperationType.Invalid;
            type.Name = VendingOperation.eOperationType.Invalid.ToString();
            log.AddOperationTypeItem(type);

            type.Id   = (int)VendingOperation.eOperationType.FeedMoney;
            type.Name = VendingOperation.eOperationType.FeedMoney.ToString();
            log.AddOperationTypeItem(type);

            type.Id   = (int)VendingOperation.eOperationType.GiveChange;
            type.Name = VendingOperation.eOperationType.GiveChange.ToString();
            log.AddOperationTypeItem(type);

            type.Id   = (int)VendingOperation.eOperationType.PurchaseItem;
            type.Name = VendingOperation.eOperationType.PurchaseItem.ToString();
            log.AddOperationTypeItem(type);

            var users    = db.GetUserItems();
            var products = db.GetProductItems();

            double runningTotal = 0.0;

            foreach (var user in users)
            {
                VendingOperation op = new VendingOperation();
                op.OperationType = VendingOperation.eOperationType.FeedMoney;
                op.Price         = 20.0;
                op.RunningTotal  = runningTotal += op.Price;
                op.TimeStamp     = DateTime.UtcNow;
                op.UserId        = user.Id;
                log.LogOperation(op);

                op.OperationType = VendingOperation.eOperationType.FeedMoney;
                op.Price         = 10.0;
                op.RunningTotal  = runningTotal += op.Price;
                op.TimeStamp     = DateTime.UtcNow;
                op.UserId        = user.Id;
                log.LogOperation(op);

                foreach (var product in products)
                {
                    op = new VendingOperation();
                    op.OperationType = VendingOperation.eOperationType.PurchaseItem;
                    op.Price         = product.Price;
                    op.RunningTotal  = runningTotal - op.Price;
                    op.TimeStamp     = DateTime.UtcNow;
                    op.UserId        = user.Id;
                    op.ProductId     = product.Id;
                    log.LogOperation(op);
                }

                op.OperationType = VendingOperation.eOperationType.GiveChange;
                op.Price         = runningTotal;
                runningTotal     = 0.0;
                op.RunningTotal  = runningTotal;
                op.TimeStamp     = DateTime.UtcNow;
                op.UserId        = user.Id;
                op.ProductId     = BaseItem.InvalidId;
                log.LogOperation(op);
            }
        }
 public void AddOperationTypeItem(OperationTypeItem item)
 {
     // do nothing intentionally
 }
Пример #7
0
 public void AddOperationTypeItem(OperationTypeItem item)
 {
     _types.Add(item);
 }