Ejemplo n.º 1
0
        public async Task <int> CreateItem(MenuItemModel model)
        {
            try
            {
                using (SqlConnection db =
                           new SqlConnection(connectionString))
                {
                    await db.OpenAsync();

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

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


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

                    string qry = "UPDATE MenuItems SET [Name]=@Name, [Catergory]=@Catergory,[Image]=@Image,[Modified]=@Modified " +
                                 "WHERE Id=@Id";
                    await db.QueryAsync <int>(qry, model);

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

            return(false);
        }