Example #1
0
        public async Task <int> CreateItem(MenuIngredientModel model)
        {
            try
            {
                using (SqlConnection db =
                           new SqlConnection(connectionString))
                {
                    await db.OpenAsync();

                    string qry = "INSERT INTO MenuIngredients ([UserId],[Name],[Catergory],[Added],[Modified]) " +
                                 "VALUES (" +
                                 "@UserId,@Name,@Catergory,@Added,@Modified); SELECT CAST(SCOPE_IDENTITY() as int)";
                    var result = await db.QueryAsync <int>(qry, model);

                    return(result.Single());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("CreateItem exception " + ex.Message);
            }


            return(-1);
        }
Example #2
0
        public async Task <bool> UpdateItem(MenuIngredientModel model)
        {
            try
            {
                using (SqlConnection db =
                           new SqlConnection(connectionString))
                {
                    await db.OpenAsync();

                    string qry = "UPDATE MenuIngredients SET [Name]=@Name, [Type]=@Type,[Modifed]=@Modifed " +
                                 "WHERE Id=@Id";
                    await db.QueryAsync(qry, model);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("UpdateMachine exception " + ex.Message);
            }

            return(false);
        }